Re:A high-performance, zero-overhead, extensible Python comp...
by RogerL on Wednesday September 18, 2024 @07:02PM
(#41586577)
return [key, value]
[ Parent
| on HN ]
Re:A high-performance, zero-overhead, extensible Python comp...
by ghxst on Wednesday September 18, 2024 @09:39PM
(#41587613)
Why would you do this over `return key, value` which produces a tuple? Just curious.
Re:A high-performance, zero-overhead, extensible Python comp...
by dgan on Thursday September 19, 2024 @01:31AM
(#41588829)
Not the parent, but i return heterogeneous lists of the same length to the excel to be used by xlwings. The first row being the headers, but every row below is obviously heterogeneous
Re:A high-performance, zero-overhead, extensible Python comp...
by 0xDEADFED5 on Thursday September 19, 2024 @04:52AM
(#41589897)
javascript refugee?
Re:A high-performance, zero-overhead, extensible Python comp...
by slightwinder on Thursday September 19, 2024 @08:23AM
(#41591069)
To quote the Zen of Python:
Explicit is better than implicit.
Readability counts.
Re:A high-performance, zero-overhead, extensible Python comp...
by ErikBjare on Thursday September 19, 2024 @02:20PM
(#41594736)
How does that apply in this case?
Re:A high-performance, zero-overhead, extensible Python comp...
by slightwinder on Friday September 20, 2024 @07:40AM
(#41600990)
"return key, value" is implicit. While "return [key, value]" is explicitly telling the full return-value. And it's (for me) more readable than "return (key, value)".
Re:A high-performance, zero-overhead, extensible Python comp...
by Nab443 on Saturday September 21, 2024 @01:16AM
(#41607670)
I don't see how "return (key, value)" is less readable than it's list counterpart. Now, why using a list that can grow, and so takes more space and maybe less efficient, for something that should not?
Re:A high-performance, zero-overhead, extensible Python comp...
by slightwinder on Tuesday September 24, 2024 @08:38AM
(#41635857)
"return (key, value)" can be read as a function-call. Especially as space after the function-name is allowed in python. And performance on that level is no serious topic in python anyway. But this is mainly just a personal preference.
Re:A high-performance, zero-overhead, extensible Python comp...
by ghxst on Sunday September 22, 2024 @02:24PM
(#41618891)
A list and tuple are not the same thing. There could be reasons to require a list explicitly but I couldn't really think of any obvious ones which is why I asked.
Re:A high-performance, zero-overhead, extensible Python comp...
by Myrmornis on Thursday September 19, 2024 @08:05AM
(#41590916)
You should use a tuple there: it's a collection of fixed size where each slot has an identity. (There's a common confusion in Python circles that the main point of tuples is immutability; that's not so).