-1

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....

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'], ...]
Talirion
  • 9
  • 2
  • 1
    I can't say for sure because I'm finding this a bit unclear, but the problem is almost surely explained [here](https://stackoverflow.com/questions/240178/list-of-lists-changes-reflected-across-sublists-unexpectedly). Don't use sequence multiplication when the inner elements are mutable (like you're doing in `[[None] * len(evts)] * len(evts[0])`). – Carcigenicate Jul 28 '21 at 13:50
  • thank you so much, your Link helped me out ... so clear now but it was strange before i read that :) – Talirion Jul 28 '21 at 14:14

1 Answers1

0
tmpdata_surprise = [[None] * len(evts)] * len(evts[0])
tmpdata = [[None]*len(evts)for _ in range(len(evts[0]))]
Talirion
  • 9
  • 2