Search code examples
pythonpython-3.xlistgeneratorchain

how can i chain two none stop lists in python3?


I have two functions generate two none stop lists, I want to print both list, but in chain function, the second list only start to print once the first list is finished, how can I print both lists, but in turns

generator = chain(nonestoplist1(), nonestoplist2())
for item in generator:
  print(item)

like:

first_list=[1,2,3,4,5,6,......]

second_list=[a,b,c,d,e,f,g,.....]

generator print:

1,a,2,b,3,c,4,d,.....


Solution

  • for item1, item2 in zip(nonestoplist1(), nonestoplist2()):
        print(item1)
        print(item2)