简体   繁体   English

从其他两个列表的值构建新列表不起作用

[英]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.

相关问题 如何添加一个新列,该列将包含来自其他列的两个列表的公共值列表 - how to add a new column that will contain a list of common values from two lists from other columns Python - 从其他两个列表随机生成一个新列表 - Python - Generating a New List Randomly From Two Other Lists 当我将其他列表中的值放入一个新列表并将新列表放在if语句中时,为什么它不起作用? - Why doesn't it work when I place values from other lists into a new one and place the new list in an if statement? 从其他列表python的平均值制作新列表 - Making new list from average values of other lists python 拆分两个列表,并将数据从一个列表分配到另一个列表中的值 - Splitting two lists and assigning data from one list to values in the other 使用两个先前列表中的值创建新列表 - Creating new list with values from two prior lists 两个列表:结合另一个列表的值 - Two lists: Combine on values of the other list 根据另外两个列表中的值创建列表 - create list based on values in two other lists 将两个 LISTS 值的 SUM 添加到新 LIST - Add SUM of values of two LISTS into new LIST 如何一次遍历两个列表列表,并用另一个列表替换一个列表中的值? - How to loop through two list of lists at once and replace values from one list with the other list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM