我需要编写一个函数,该函数接受一个字典,其键等于名称,值是字典。嵌套在其中的字典的键等于任务,其值等于任务花费的小时数。我需要返回一个字典,其中任务作为键,它的值是一个字典,名称作为键,它的值是小时。
我不知道如何访问嵌套字典中的值,因此嵌套字典中的值与键相同。这是我所拥有的:
def sprintLog(sprnt):
new_dict = {}
new_dict = {x: {y: y for y in sprnt.keys() if x in sprnt[y]} for l in sprnt.values() for x in l}
return new_dict如果我传入字典,例如:
d = {'Ben': {'task1': 5}, 'alex': {'task1': 10, 'task2': 4}}我期待得到一本字典,例如:
new_dict = {'task1': {'Ben': 5, 'alex': 10}, 'task2': {'alex': 4}}但我现在得到的是:
new_dict = {'task1': {'Ben': 'Ben', 'alex': 'alex'}, 'task2': {'alex': 'alex'}}
蓝山帝景
慕桂英546537
猛跑小猪
慕森卡
随时随地看视频慕课网APP
相关分类