32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
# HumanEval/95
|
|
# Loki Mode Multi-Agent Solution
|
|
# Attempts: 1
|
|
# Passed: True
|
|
|
|
def check_dict_case(dict):
|
|
"""
|
|
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"}) should return True.
|
|
check_dict_case({"a":"apple", "A":"banana", "B":"banana"}) should return False.
|
|
check_dict_case({"a":"apple", 8:"banana", "a":"apple"}) should return False.
|
|
check_dict_case({"Name":"John", "Age":"36", "City":"Houston"}) should return False.
|
|
check_dict_case({"STATE":"NC", "ZIP":"12345" }) should return True.
|
|
"""
|
|
if len(dict) == 0:
|
|
return False
|
|
|
|
all_lower = True
|
|
all_upper = True
|
|
|
|
for key in dict:
|
|
if not isinstance(key, str):
|
|
return False
|
|
if not key.islower():
|
|
all_lower = False
|
|
if not key.isupper():
|
|
all_upper = False
|
|
|
|
return all_lower or all_upper |