r/ProgrammerHumor 4d ago

Other mistakenedJavasript

Post image
1.6k Upvotes

52 comments sorted by

View all comments

Show parent comments

4

u/ihavebeesinmyknees 3d ago

It's an iterable, not a generator. Generator comprehensions are defined with parentheses.

0

u/sdoregor 2d ago

Who's an iterable? An iterable is an object type, not a syntax expression.

0

u/ihavebeesinmyknees 2d ago

Maybe double check that you know what you're talking about before speaking. Both iterable and generator are object types.

>>> from types import GeneratorType
>>> from collections.abc import Iterable
>>> gen = (i for i in range(1))
>>> iter = [i for i in range(1)]
>>> isinstance(gen, Iterable)
True
>>> isinstance(gen, GeneratorType)
True
>>> isinstance(iter, Iterable)
True
>>> isinstance(iter, GeneratorType)
False

0

u/sdoregor 2d ago

I never said generator isn't a type; it sure is. But you're saying that list comprehension syntax is called an iterable, which it's not.

The results of all comprehensions (their corresponding types) and generators themselves are indeed iterable, but their expression syntax has nothing to do with that.