How to generically transform a list?

Kent Johnson kent at pondview.mv.com
Thu Aug 26 16:47:20 EDT 2004


Your second method can easily be rewritten using list comprehensions:
>>> the_list = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']]
>>> returnList = [2,1]
>>> new_list = [ [row[i] for i in returnList] for row in the_list ]
>>> new_list
[[11, 1], [22, 2], [33, 3]]

Kent



More information about the Python-list mailing list