Is there faster ways to make tuple comprehensions? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

18th Jan 2020, 8:53 PM
Seb TheS
Seb TheS - avatar
4 Answers
+ 4
tuple([... for ... in ...])
18th Jan 2020, 9:12 PM
Diego
Diego - avatar
+ 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.
18th Jan 2020, 9:56 PM
Diego
Diego - avatar
+ 1
Diego Makes no sense, but it's faster, thanks.
18th Jan 2020, 9:15 PM
Seb TheS
Seb TheS - avatar
+ 1
@Diego Is it supposed to work like that or did you just accidentally find out it was faster?
18th Jan 2020, 9:23 PM
Seb TheS
Seb TheS - avatar