gpt4 book ai didi

Python - 集合

转载 作者:行者123 更新时间:2023-11-30 23:37:33 27 4
gpt4 key购买 nike

我是 Python 新手,想知道如何使用键在字典中存储不同数据类型的列表

例如 -

{[Key1,int1,int1,String1] , [Key2,int2,int2,String2], [Key3,int3,int3,String3] }

如何创建字典并添加这些元素?

最佳答案

假设您的意思是您的数据是:

lst = [[Key1,int1,int1,String1] , [Key2,int2,int2,String2], [Key3,int3,int3,String3]]

然后你可以这样做:

{x[0]:x[1:] for x in lst}

你实际上是在尝试从一堆列表中创建一个set - 但这是行不通的,因为list对象不是可散列。

关于Python - 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15440015/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com