How to join two generators in Python?

后端 未结 12 1572
醉酒成梦
醉酒成梦 2020-11-28 22:40

I want to change the following code

for directory, dirs, files in os.walk(directory_1):
    do_something()

for directory, dirs, files in os.walk(directory_2         


        
12条回答
  •  无人及你
    2020-11-28 23:36

    Simple example:

    from itertools import chain
    x = iter([1,2,3])      #Create Generator Object (listiterator)
    y = iter([3,4,5])      #another one
    result = chain(x, y)   #Chained x and y
    

提交回复
热议问题