Different "look and feel" of some built-in functions

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Sep 24 19:15:01 EDT 2021


On 25/09/21 10:15 am, Steve Keller wrote:
> BTW, I like how the min() and max() functions allow both ways of being
> called.

That wouldn't work for set.union and set.intersection, because as
was pointed out, they're actually methods, so set.union(some_seq)
is a type error:

 >>> a = {1, 2}
 >>> b = {3, 4}
 >>> set.union([a, b])
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
TypeError: descriptor 'union' for 'set' objects doesn't apply to a 
'list' object

I suppose they could be fiddled somehow to make it possible, but
that would be turning them into special cases that break the rules.
It would be better to provide separate functions, as was done with
sum().

-- 
Greg


More information about the Python-list mailing list