When is not a good time to use python generators?

前端 未结 9 902
不思量自难忘°
不思量自难忘° 2020-11-27 10:27

This is rather the inverse of What can you use Python generator functions for?: python generators, generator expressions, and the itertools module are some of m

9条回答
  •  攒了一身酷
    2020-11-27 10:46

    As you mention, "This especially makes sense for large datasets", I think this answers your question.

    If your not hitting any walls, performance-wise, you can still stick to lists and standard functions. Then when you run into problems with performance make the switch.

    As mentioned by @u0b34a0f6ae in the comments, however, using generators at the start can make it easier for you to scale to larger datasets.

提交回复
热议问题