substitution of list elements

antar2 desothier at yahoo.com
Fri Jul 18 08:33:57 EDT 2008


I want to replace each first element in list 5 that is equal to the
first element of the list of lists4 by the fourth element. I wrote
following code that does not work:

list4 = [['1', 'a', 'b', 'c'], ['2', 'd', 't', 'e'], ['8', 'g', 'q',
'f']]
list5 = ['1', '2', '3']

for j in list4:
  for k in list5:
    if j[0] == k:
	    k = j[3]
print list5
Wanted result: ['c', 'e', '3']

thanks!



More information about the Python-list mailing list