Adding elements to python generators

前端 未结 4 1611
醉酒成梦
醉酒成梦 2020-12-13 19:56

Is it possible to append elements to a python generator?

I\'m currently trying to get all images from a set of disorganized folders and write them to a new directory

4条回答
  •  借酒劲吻你
    2020-12-13 20:44

    Like this.

    def threeGens( i, j, k ):
        for x in range(i):
           yield x
        for x in range(j):
           yield x
        for x in range(k):
           yield x
    

    Works well.

提交回复
热议问题