substitution of list elements
Wolfram Kraus
kraus at hagen-partner.de
Fri Jul 18 08:41:18 EDT 2008
Am 18.07.2008 14:33, antar2 schrieb:
> 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:
for i,k in enumerate(list5):
> if j[0] == k:
> k = j[3]
list5[i] = j[3]
> print list5
> Wanted result: ['c', 'e', '3']
>
> thanks!
You didn't replace the list element itself.
HTH,
Wolfram
More information about the Python-list
mailing list