When is not a good time to use python generators?

前端 未结 9 915
不思量自难忘°
不思量自难忘° 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:58

    Profile, Profile, Profile.

    Profiling your code is the only way to know if what you're doing has any effect at all.

    Most usages of xrange, generators, etc are over static size, small datasets. It's only when you get to large datasets that it really makes a difference. range() vs. xrange() is mostly just a matter of making the code look a tiny little bit more ugly, and not losing anything, and maybe gaining something.

    Profile, Profile, Profile.

提交回复
热议问题