【问题标题】:adding list of items into the values of Dictionary将项目列表添加到 Dictionary 的值中
【发布时间】:2021-10-24 09:15:43
【问题描述】:

假设我有一个列表 [10,9,8,7] 我有一个 my_dict {4:0, 3: 0, 2: 0 , 1 : 0}

我是 Python 新手,我已经尝试研究如何解决这个问题,但我仍然找不到答案。我想将列表添加到 my_dict 的值中,我应该如何处理?

my_list = [10,9,8,7]
my_dict = {4:0, 3: 0, 2: 0 , 1 : 0}

【问题讨论】:

    标签: python-3.x dictionary


    【解决方案1】:

    这就是你要找的东西

    for index, (key,value) in enumerate(my_dict.items()):
       my_dict[key] = my_list[index]
    print(my_dict)
    

    【讨论】:

    • 是的,这很好!没注意,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多