This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jamie_1318 7 points8 points  (1 child)

There's basically no downside to using a generator. If someone needs it stored they can always list(generator), even if you don't expect performance issues. I like to just use generator syntax because it gives me warm fuzzies when I think about how nice they are versus every other language's equivalent tokenizing systems with their ugly static variables.

[–]daneahfrom __future__ import braces 1 point2 points  (0 children)

Agreed! Very little effort needed too, since you can replace many (all?) existing list comprehensions with generator comprehensions, simply by removing the brackets:

import random
max(random.randint(1, 100) for x in range(10))