1 回答
TA贡献1862条经验 获得超7个赞
将每个元素转换为元组,然后将元组拆分为变量或将每个内部元素附加到列表中。
分割元组:
info = [[30.22,-81.88,'VFR'],[27.18,-80.22,'VFR'], [35.35,-89.87,'MVFR']]
lat = [None] * len(info)
long = [None] * len(info)
cat = [None] * len(info)
for i,e in enumerate(info):
lat[i], long[i], cat[i] = tuple(e)
print(lat)
print(long)
print(cat)
附加内部元素:
info = [[30.22,-81.88,'VFR'],[27.18,-80.22,'VFR'], [35.35,-89.87,'MVFR']]
lat = []
long = []
cat = []
for e in info:
lat.append(e[0])
long.append(e[1])
cat.append(e[2])
print(lat)
print(long)
print(cat)
列表理解也是一种选择:
info = [[30.22,-81.88,'VFR'],[27.18,-80.22,'VFR'], [35.35,-89.87,'MVFR']]
lat = [e[0] for e in info]
long = [e[1] for e in info]
cat = [e[2] for e in info]
print(lat)
print(long)
print(cat)
全部都有相同的结果:
[30.22, 27.18, 35.35]
[-81.88, -80.22, -89.87]
['VFR', 'VFR', 'MVFR']
添加回答
举报