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

前端 未结 6 1307
庸人自扰
庸人自扰 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:28

    They do very similar things. For small number of iterables itertools.chain(*iterables) and itertools.chain.from_iterable(iterables) perform similarly.

    The key advantage of from_iterables lies in the ability to handle large (potentially infinite) number of iterables since all of them need not be available at the time of the call.

提交回复
热议问题