Adding elements to python generators

前端 未结 4 1609
醉酒成梦
醉酒成梦 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:36

    You are looking for itertools.chain. It will combine multiple iterables into a single one, like this:

    >>> import itertools 
    >>> for i in itertools.chain([1,2,3], [4,5,6]):
    ...     print(i)
    ... 
    1
    2
    3
    4
    5
    6
    

提交回复
热议问题