例如:
synonyms_dict = {'look': ['gaze', 'see', 'glance', 'watch', 'peruse'],
'put': ['place', 'set', 'attach', 'keep', 'save', 'set aside',
'effect',
'achieve', 'do', 'build'],
'beautiful': ['pretty', 'lovely', 'handsome', 'dazzling', 'splendid',
'magnificent'],
'slow': ['unhurried', 'gradual', 'leisurely', 'late', 'behind', 'tedious',
'slack'],
'dangerous': ['perilous', 'hazardous', 'uncertain']}
remove_short_synonyms(synonyms_dict)
print("1.")
print_dict_in_key_order(synonyms_dict)
synonyms_dict = {'come': ['approach', 'advance', 'near', 'arrive', 'reach'],
'show': ['display', 'exhibit', 'present', 'point to', 'indicate', 'explain',
'prove', 'demonstrate', 'expose'],
'good': ['excellent', 'fine', 'superior', 'wonderful', 'grand', 'superb',
'edifying'],
'bad': ['evil', 'immoral', 'wicked', 'contaminated', 'spoiled', 'defective',
'substandard', 'faulty', 'improper', 'inappropriate']}
remove_short_synonyms(synonyms_dict)
print("2.")
print_dict_in_key_order(synonyms_dict)
我试图从每个对应的同义词列表中删除少于7个字符的所有同义词,并且函数对每个对应的同义词列表进行排序。我试过这个功能。在
^{pr2}$期望:
beautiful : ['dazzling', 'handsome', 'magnificent', 'splendid']
dangerous : ['hazardous', 'perilous', 'uncertain']
look : []
put : ['achieve', 'set aside']
slow : ['gradual', 'leisurely', 'tedious', 'unhurried']
2.
bad : ['contaminated', 'defective', 'immoral', 'improper', 'inappropriate',
'spoiled', 'substandard']
come : ['advance', 'approach']
good : ['edifying', 'excellent', 'superior', 'wonderful']
show : ['demonstrate', 'display', 'exhibit', 'explain', 'indicate', 'point
to', 'present']
不要从原始版本中删除,只需使用dictionary comprehension重建一个过滤后的版本,并在值上使用max-size过滤器,然后馈送到
sorted
对值列表进行排序:结果:
^{pr2}$相关问题 更多 >
编程相关推荐