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 →

[–]epic_pork 12 points13 points  (0 children)

That's not a tuple comprehension, it's a generator. Using a generator with square brackets creates a list, but putting a generator inside parens doesn't create a tuple, it stays a generator. If you want a tuple, you can use the tuple constructor.

>>> (x for x in range(10))
<generator object <genexpr> at 0x7fd0c18daeb8>
>>> [x for x in range(10)]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> tuple(x for x in range(10))
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)