Merging two lists of data (Pythonic way)
Georg Brandl
g.brandl-nospam at gmx.net
Thu Feb 16 16:14:47 EST 2006
Dave Hansen wrote:
> On Thu, 16 Feb 2006 12:51:24 -0800 in comp.lang.python, "SMB"
> <sean at buildingonline.com> wrote:
>
>>
>>"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?
>>>
>>
>>That is exactly what I was looking for. I will have to take a look at map.
>
> You might also look at list comprehensions. Replacing the first line
> in the above with
>
> codes = [x[0] for x in list1]
>
> should yield the same result.
Even another way:
import operator
codes = map(operator.itemgetter(0), list1)
Georg
More information about the Python-list
mailing list