What is the difference between chain and chain.from_iterable in itertools?

前端 未结 6 1325
庸人自扰
庸人自扰 2020-12-07 20:05

I could not find any valid example on the internet where I can see the difference between them and why to choose one over the other.

6条回答
  •  广开言路
    2020-12-07 20:22

    Another way to see it:

    chain(iterable1, iterable2, iterable3, ...) is for when you already know what iterables you have, so you can write them as these comma-separated arguments.

    chain.from_iterable(iterable) is for when your iterables (like iterable1, iterable2, iterable3) are obtained from another iterable.

提交回复
热议问题