[英]build a new list from values of two other lists does not work
i have a problem and cant find an answer inside the Forum so i hope someone will be able to help me because it seams i cant figure it aout by myself :)我有一个问题,无法在论坛中找到答案,所以我希望有人能够帮助我,因为它接缝我无法自己解决:)
def loadData(uid):
// ...
return [uid,u'',u'',u'',u'',u'',u'',u'',u'',]
evts = []
uids = [7, 43,]
for uid in uids:
evts.append(loadData(uid))
tmpdata = [[None] * len(evts)] * len(evts[0])
print tmpdata
for iKey in range(len(tmpdata)):
for iEvt in range(len(tmpdata[iKey])):
tmpdata[iKey][iEvt] = evts[iEvt][iKey]
print iKey, iEvt, tmpdata[iKey]
print tmpdata
Normaly i want to create a list with each attribute inside athe sub list, so for example the 0,0 and 0,1 index had to be the uid values of each data (7& 43) but as you see here it does not work as wanted....通常,我想在子列表中创建一个包含每个属性的列表,因此例如 0,0 和 0,1 索引必须是每个数据的 uid 值(7 和 43),但正如您在此处看到的那样,它不起作用通缉....
result:
[[None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None],
[None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None],
[None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None],
[None, None], [None, None], [None, None], [None, None], [None, None], [None, None]]
0
0[7, None]
0
1[7, 43]
1
0[u'Matthias Reim & Band', 43]
1
1[u'Matthias Reim & Band', u'Der Nussknacker']
...
[[None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None],
[None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None],
[None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None], [None, None],
[None, None], [None, None], [None, None], [None, None], [None, None], [None, None]]
i want a result like:我想要这样的结果:
[[7, 43], [u'Matthias Reim & Band', u'Der Nussknacker'], ...]
tmpdata_surprise = [[None] * len(evts)] * len(evts[0])
tmpdata = [[None]*len(evts)for _ in range(len(evts[0]))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.