我想按字典中元组的元素来组织
我正在写一个组织元组元素的函数
grade = {'A+': 4.3, 'A': 4.0, 'A-': 3.7,
'B+': 3.3, 'B': 3.0, 'B-': 2.7,
'C+': 2.3, 'C': 2.0, 'C-': 1.7,
'D+': 1.3, 'D': 1.0, 'D-': 0.7,
'F' : 0.0}
subject = {'math': {('Tom', 'A+'), ('Kevin','B+')},
'History': {('Kate', 'C+'),('Eric','C'),('Hannah','A-')},
'English': {('Eli', 'B-')}}`
我想要像这样的输出
{'A': {'math':{'Tom'}, 'history': {'Hannah'}},
'B':{'math': {'Kevin'}, 'English': {'Eli'}},
'C':{'History': {'Kate', 'Eric'}}}
我不知道如何删除后缀并按元素组织。。 我想我需要几本字典和小册子
使用
collections.defaultdict
例如:
输出:
相关问题 更多 >
编程相关推荐