substitution of list elements

antar2 desothier at
Fri Jul 18 14:33:57 CEST 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',
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']


More information about the Python-list mailing list