You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defcheck_dict_case(dict: Dict[str, str]) ->bool:
""" Given a dictionary, return True if all keys are strings in lower case or all keys are strings in upper case, else return False. The function should return False is the given dictionary is empty. Examples: # >>> check_dict_case({"a":"apple", "b":"banana"}) # True # >>> check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) # False # >>> check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) # False # >>> check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) # False # >>> check_dict_case({"STATE":"NC", "ZIP":"12345" }) True """iflen(dict.keys()) ==0:
returnFalseelse:
state="start"forkeyindict.keys():
ifisinstance(key, str) ==False:
state="mixed"breakifstate=="start":
ifkey.isupper():
state="upper"elifkey.islower():
state="lower"else:
breakelif (state=="upper"andnotkey.isupper()) or (state=="lower"andnotkey.islower()):
state="mixed"breakelse:
breakreturnstate=="upper"orstate=="lower"
In the solution above, the last break statement should instead be continue
current solution would work because the case switch occurs in the second element, and that python happens to preserve the order in which the key, value pairs are iterated.
In the solution above, the last
break
statement should instead becontinue
In the current test
current solution would work because the case switch occurs in the second element, and that python happens to preserve the order in which the key, value pairs are iterated.
If the test were changed to
This solution would have failed the test
The text was updated successfully, but these errors were encountered: