如何使用python基础编程语言来解决下面那两道题?
发布网友
发布时间:2022-04-19 13:23
我来回答
共1个回答
热心网友
时间:2023-06-15 05:16
灞曞紑鍏ㄩ儴def remove_short_synonyms(dic):
for i in dic:
for n in range(len(dic[i])):
if len(dic[i][n]) < 8:
dic[i][n] = ''
while '' in dic[i]:
dic[i].remove('')
def print_dict_in_key_order(dic):
order = [i for i in dic]
order.sort()
for k in order:
print(k, ':', sorted(dic[k]))
synonyms_dict = {'look': ['gaze', 'see', 'glance', 'watch', 'perusr'],
'put': ['place', 'set', 'attach', 'keep', 'save', 'set aside', 'effect',
'achieve', 'do', 'build'],
'beautiful': ['pretty', 'lovely', 'handsome', 'dazzling', 'splendid',
'magnificent'],
'slow': ['unhurried', 'graal', 'leisurely', 'late', 'behind', 'tedious', 'slack'],
'danderous': ['perilous', 'hazardous', 'uncertain']}
remove_short_synonyms(synonyms_dict)
print('1.')
print_dict_in_key_order(synonyms_dict)
print()
synonyms_dict = {'come': ['approach', 'advance', 'near', 'arrive', 'reach'],
'show': ['display', 'exhibit', 'present', 'note', 'point to', 'indicate',
'explain', 'reveal', 'prove', 'demonstrate', 'expose'],
'good': ['excellent', 'fine', 'superior', 'wonderful', 'grand', 'superb', 'edifying'],
'bad': ['evil', 'immoral', 'wicked', 'rotten', 'contaminated', 'spoiled',
'defective', 'substandard', 'faulty', 'improper', 'inappropriate']}
remove_short_synonyms(synonyms_dict)
print('2.')
print_dict_in_key_order(synonyms_dict)
print()