1

I am using list comprehension in order to produce a number of zip objects:

[ zip(a, b[i]) for i in range(0, 1) ]

>>> [<zip object at 0x10a216b88>, <zip object at 0x10a216c08>]

How can I concatenate both zip objects into a single list?

If for example <zip object at 0x10a216b88> has:

(a, b)
(a, c)

and <zip object at 0x10a216c08>:

(f, g)
(f, w)

the desired output would be:

[(a, b), (a, c), (f, g), (f, w)]
Tokyo
  • 753
  • 1
  • 10
  • 25

1 Answers1

2

Use itertools.chain.from_iterable:

>>> import itertools
>>> l = [zip(range(3), range(3)), zip(range(3), range(3))]
>>> l
[<zip object at 0x7f7e80912408>, <zip object at 0x7f7e840a18c8>]
>>> list(itertools.chain.from_iterable(l))
[(0, 0), (1, 1), (2, 2), (0, 0), (1, 1), (2, 2)]
Netwave
  • 40,134
  • 6
  • 50
  • 93