Merging two lists of data (Pythonic way)

SMB sean at buildingonline.com
Thu Feb 16 15:59:07 EST 2006


"Jonathan Gardner" <jgardner at jonathangardner.net> wrote in message 
news:1140122391.823206.74580 at g14g2000cwa.googlegroups.com...
> codes = map(lambda x: x[0], list1)
> for d in list2:
>  if d['code'] in codes:
>    d['VERIFIED'] = 1
>
> Is this what you were looking for?
>

Actually, this is not exactly what I was looking for.  I failed to realize 
what map did, in this case using the labmda x: x[0] on each item of the list 
returning a list of the key numbers.  The problem is that the changes made 
to my dictionary (in my example dictionary["VERIFIED"]=1) needs to be based 
on the other values in each list in LIST1.

In my example LIST1 was defined as
[[5L, 1L, 1L, 'Personal Information'], [14L, 2L, 1L, '']]

So, the dictionary changes would be involving mylist[1:] for each mylist in 
LIST1 based on the comparison to mylist[0]...

Thank again 





More information about the Python-list mailing list