python 中如何将一个list 转成dict,且将第一个元素作为key,而后四个作为value?
发布网友
发布时间:2022-04-18 02:25
我来回答
共2个回答
热心网友
时间:2022-04-18 03:54
mylist = []
for a in range(0,10000):
mylist.append((a,a+1,a+2,a+3,a+4))
myDict = {}
for key in mylist:
myDict[key[0]] = key[1:]
print myDict
热心网友
时间:2022-04-18 05:12
#!/usr/bin/env python
# -*- coding: utf-8 -*-
list_ = [(1, 0.2,90,24,21),(2, 0.2,90,24,21),(3, 0.2,90,24,21)]
dict_ ={i[0]:i[1:] for i in list_}
#dict_ ={str(i[0]):i[1:] for i in list_}
print dict_
=============== RESTART: C:/Users/Administrator/Desktop/tt.py ===============
{1: (0.2, 90, 24, 21), 2: (0.2, 90, 24, 21), 3: (0.2, 90, 24, 21)}
>>>