-1

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,.....

yin
  • 85
  • 1
  • 1
  • 4
  • You cn zip them nd iterate o ver the tuples zipped – E.Serra Sep 27 '18 at 15:02
  • This isn't quite the same as the suggested duplicate, because you want to flatten the inputs into a single iterable. You're looking for `chain.from_iterable(zip(gen1, gen2))`. – Patrick Haugh Sep 27 '18 at 15:10

1 Answers1

0
for item1, item2 in zip(nonestoplist1(), nonestoplist2()):
    print(item1)
    print(item2)
Reupiey
  • 277
  • 1
  • 9