我想将列表更改为字典,并且还想将列表的第一个元素作为字典的键,其他元素将是字典中该键的结果。提前致谢。
这就是我所拥有的:
lst = ['a', 'b', 'c', 'd']
print (list)
['a', 'b', 'c', 'd']
这就是我想要的:
dic = {'a':['b', 'c', 'd']}
print(dic)
{'a': ['b', 'c', 'd']}
或
print (dic['a'])
['b', 'c', 'd']
最佳答案
你可以尝试:
lst = ['a', 'b', 'c', 'd']
dct = {lst[0]:lst[1:]}
它会给你想要的结果
关于python - 想要将列表的元素更改为Python中的字典键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62459349/