List to merge different lists in python

I need to build many sample data, each of which is stored in a list of integers. I want to create a list of many concatenated lists to build it with an enumeration (big_list) to get the x coordinate with a fixed offset. My current code is:

biglist = []
for n in xrange(number_of_lists):
    biglist.extend(recordings[n][chosen_channel])
for x,y in enumerate(biglist):
    print x,y

Notes: number_of_lists and selected_channel are integer parameters defined elsewhere, and for example, print x, y (in fact, there are other instructions for plotting points.

My question is: is there a better way, such as list recognition or another operation, to achieve the same result (a combined list) without a loop and a previously declared empty list?

thank

+3
source share
2
import itertools
for x,y in enumerate(itertools.chain(*(recordings[n][chosen_channel] for n in xrange(number_of_lists))):
    print x,y

itertools.chain() . , . , .

+4
>>> import itertools
>>> l1 = [2,3,4,5]
>>> l2=[9,8,7]
>>> itertools.chain(l1,l2)
<itertools.chain object at 0x100429f90>
>>> list(itertools.chain(l1,l2))
[2, 3, 4, 5, 9, 8, 7]
+3

Source: https://habr.com/ru/post/1794627/


All Articles