r/ProgrammerHumor • • Sep 07 '26

Other mistakenedJavasript

Post image
1.6k Upvotes

55 comments sorted by

View all comments

Show parent comment

0

u/sdoregor Sep 09 '26

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

0

u/ihavebeesinmyknees Sep 09 '26

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 Sep 09 '26

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.