get list of member variables from list of class

Oliver Eichler oliver.eichler at
Fri Jan 28 03:50:47 EST 2005


what will be the fastest solution to following problem

class a:
  def __init__(self):
    self.varA = 0
    self.varB = 0    
    s.o. ...

listA = [a]*10

varA = []
varB = []

for l in listA:
  s.o. ...

I could think of:
[varA.append(l.varA) for l in listA]
[varB.append(l.varB) for l in listA]
s.o. ...

But is this faster? After all I have to iterate over listA several times.

Any better solutions?


More information about the Python-list mailing list