马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我已经写好了dictionary
seven_segment = {'0': {'a','c','d','e','b','f'},
'1': {'c','b'},
'2': {'a','d','e','b','g'},
'3': {'a','c','d','b','g'},
'4': {'g','c','f','b'},
'5': {'a','c','d','g','f'},
'6': {'a','c','d','e','g','f'},
'7': {'a','c','b'},
'8': {'a','c','d','e','b','g','f'},
'9': {'a','c','d','b','g','f'}}
题目的要求是有些灯坏了。所以在我输入
>>> guess_character(seven_segment, 'abed')
{'2', '8', '0'}
>>> guess_character(seven_segment, 'a')
{'5', '7', '6', '0', '3', '9', '2', '8'}
>>> guess_character(seven_segment, 'abcdefg')
{'8'}
我的code是这样子的:
def guess_character(display, state):
query = set(seven_segment)
candidate_set = {'1','2','3','4','5','6','7','8','9','0'}
for i in query:
try:
candidate_set = candidate_set & seven_segment[i]
except:
candidate_set = candidate_set
print(candidate_set)
return candidate_set
def guess_character(seven_segment, string):
result = set()
set1 = set(string)
for n, s in seven_segment.items():
if set1 <= s:
result.add(n)
return result
|