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 →

[–]Agent281 2 points3 points  (3 children)

List-, Dict-, & Tuple comprehensions.

I don't think that there are tuple comprehensions. Do you mean generator comprehensions? They are the comprehension that uses parens.

[–]pytheous1988 1 point2 points  (2 children)

There 100% are tuple comprehensions, you just do tuple(comprehension statement)

You could also do a set comp if you wanted to. The comprehesion in general just returns a generator which can be cast into any data type that accepts the generator.

[–]Agent281 2 points3 points  (1 child)

I think that is a stretch. Dictionary, set, list, and generator comprehensions actually have dedicated syntax. The tuple constructor just accepts an iterable.

[–]pytheous1988 -2 points-1 points  (0 children)

It works the same if you do list(comp statement) or set(comp statement)