merge list of tuples with list

Paul Rubin no.email at nospam.invalid
Tue Oct 19 21:26:19 EDT 2010


Daniel Wagner <brocki2301 at googlemail.com> writes:
>> > My short question: 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) ...
> the output should look like:
> a = [(1,2,3,7), (4,5,6,8)]

That is not really in the spirit of tuples, which are basically supposed
to be of fixed size (like C structs).  But you could write:

  >>> [x+(y,) for x,y in zip(a,b)]
  [(1, 2, 3, 7), (4, 5, 6, 8)]



More information about the Python-list mailing list