How to generically transform a list?

Marco Aschwanden PPNTWIMBXFFC at spammotel.com
Thu Aug 26 11:03:11 EDT 2004


Here is a proposal, but I am sure, that there is a simpler way... there is 
too much appending:

>>> the_list = [['a',1,11,'aa'], ['b',2,22,'bb'],['c',3,33,'cc']]
>>> returnList = [2,1] # user wants col 2 first followed by col 1
>>> new_list = []
>>> for row in theList:
... 	list_row = []
... 	for idx in returnList:
... 	  list_row.append(row[idx])
... 	new_list.append(list_row)
... 	
>>> new_list
[[11, 1], [22, 2], [33, 3]]




More information about the Python-list mailing list