On 20/10/2010 02:26, Paul Rubin wrote:
Daniel Wagner<brocki2...@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)]

In Python 2.x:

    zip(*zip(*a) + [b])

In Python 3.x:

    list(zip(*list(zip(*a)) + [b]))
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to