Tuple Comprehension ???
Thomas Passin
list1 at tompassin.net
Tue Feb 21 13:22:37 EST 2023
On 2/21/2023 12:32 PM, Axy via Python-list wrote:
> On 21/02/2023 04:13, Hen Hanna wrote:
>>
>> (A) print( max( * LisX ))
>> (B) print( sum( * LisX )) <------- Bad
>> syntax !!!
>>
>> What's most surprising is.... (A) is ok, and (B) is not.
>>
>> even tho' max() and sum() have (basically) the same
>> syntax... ( takes one arg , whch is a list )
They **don't** have basically the same signature, though. max() takes
either an iterable or two or more numbers. Using max(*list_) presents
it with a series of numbers, so that's OK.
sum() takes just one iterable (plus an optional start index). Using
sum(*list_) presents it with a series of numbers, and that does not
match its signature.
Check what I said:
>>> help(sum)
Help on built-in function sum in module builtins:
sum(iterable, /, start=0)
Return the sum of a 'start' value (default: 0) plus an iterable of
numbers
>>> help(max)
Help on built-in function max in module builtins:
max(...)
max(iterable, *[, default=obj, key=func]) -> value
max(arg1, arg2, *args, *[, key=func]) -> value
Why they have different signatures may be lost to the whims of history
and backwards compatibility...
>>
>>
>>
>> i've been programming for many years... ( just knew to Python )
>
> LOL, python is full of surprises. I'd definitely step into the same
> piece of... Someday.
>
> Of course 'Builtin functions' section explains that, but the
> inconsistency is weird.
>
> My response is absolutely useless, just two cents on the issue. Maybe
> someone will fix that.
>
> Axy.
More information about the Python-list
mailing list