[Tutor] this group and one liners

avi.e.gross at gmail.com avi.e.gross at gmail.com
Fri Jul 8 19:49:36 EDT 2022


You are right, Alan, so max mainly does what I expect. Since generally no
arguments makes no sense for having  a maximum and one argument that is
really just one also makes little sense as it is by default the maximum (and
minimum, median, mode, ...)  then it stands to reason to treat a single
argument as a kind of collection.

However, since max[1]) works fine, and max(1) fails, it seems a tad
inconsistent. 

I note in my experiments that max("a") works but only because like many
things in python, it sees a character string as an iterator of sorts and
max("max") returns 'x' of course. Unfortunately, when that is supplied as a
list: max(["max"]) --> 'max'

 Time to move on from this topic except to say that debugging some python
constructs may need to be part of what I do if I am not careful.


-----Original Message-----
From: Tutor <tutor-bounces+avi.e.gross=gmail.com at python.org> On Behalf Of
Alan Gauld via Tutor
Sent: Friday, July 8, 2022 6:09 PM
To: tutor at python.org
Subject: Re: [Tutor] this group and one liners

On 08/07/2022 22:52, avi.e.gross at gmail.com wrote:

> We know max(1,2,3) fails as it demands an iterable like [1,2,3] 

Nope.

max(1,2,3)

works just fine for me. Its only a single value that fails:

>>> max(1,2,3)
3
>>> max(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable
>>>

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist  -  Tutor at python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list