merge list of tuples with list

Daniel Wagner brocki2301 at googlemail.com
Tue Oct 19 23:33:29 EDT 2010


SOLVED! I just found it out....

> I'm searching for a nice way to merge a list of
> tuples with another tuple or list. Short example:
> a = [(1,2,3), (4,5,6)]
> b = (7,8)
>
> After the merging I would like to have an output like:
> a = [(1,2,3,7), (4,5,6)]

The following code solves the problem:
>>> a = [(1,2,3), (4,5,6)]
>>> b = [7,8]
>>> a = map(tuple, map(lambda x: x + [b.pop(0)] , map(list, a)))
>>> a
[(1, 2, 3, 7), (4, 5, 6, 8)]

Any more efficient ways or suggestions are still welcome!

Greetings,
Daniel



More information about the Python-list mailing list