get list of member variables from list of class

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


Hi 

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:
  varA.append(l.varA)
  varB.append(l.varB)
  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?


Oliver



More information about the Python-list mailing list