+5

Is there faster ways to make tuple comprehensions?

I've so far needed to make list comprehensions using: tuple(... for ... in ...) Tuples can't be created like this: (... for ... in ...) because it is reserved for creating generators, also this: (... for ... in ...,) did not work. Like lists, dicts and sets have these: [... for ... in ...] {...:... for ... in ...} {... for ... in ...} do tuples have equivalent? I little want this because using: [... for ... in ...] seems to be little faster than: list(... for ... in ...) like you can see here: https://code.sololearn.com/cupxh0K9tTfy/#py

1/18/2020 8:53:41 PM

Seb TheS

5 Answers

New Answer

+4

tuple([... for ... in ...])

+2

I once read that list comprehensions are faster than generator comprehensions with some methods/functions. I still haven't read a well-constructed argument of the above, but the tuple() function seems to agree with it.

+1

Diego Makes no sense, but it's faster, thanks.

+1

@Diego Is it supposed to work like that or did you just accidentally find out it was faster?

0

c=tuple(i for i in range(10)) print(c)