[Python-bugs-list] [ python-Bugs-807771 ] Max and min are incorrect with one argument

SourceForge.net noreply at sourceforge.net
Mon Sep 22 15:24:38 EDT 2003


Bugs item #807771, was opened at 2003-09-17 06:49
Message generated for change (Settings changed) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=807771&group_id=5470

Category: Python Library
Group: Python 2.2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Greg Kochanski (gpk)
Assigned to: Nobody/Anonymous (nobody)
Summary: Max and min are incorrect with one argument

Initial Comment:
max(1)

raises 'TypeError: iteration over non-sequence',

when it should simply return 1



Min has the same problem.



If there is one person in a room, and you ask for the

tallest person, there is a well-defined answer.

The tallest person is the only person.

So is the shortest person.



I ran across this when I was doing

apply(max, list) / apply(min, list)

to find out the ratio of maximum to minimum entries

in a list.    With a single-element list, I expected

it to return 1, instead of raising an exception.



----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-09-22 14:24

Message:
Logged In: YES 
user_id=80475

That behavior is consequence of interpreting a single 

argument as an input sequence while interpreting multiple 

arguments as the sequence itself.



Given a single argument, Python could make some 

reasonable guesses:  max(3) --> 3  and max((3,4)) --> 4, 

but guessing is not the Pythonic way.  Also, I think max(x) 

tends to be an error condition when x is not iterable, so it 

would be unwise to simply return x and let the error pass 

silently.



If it makes you feels better, you *are* the tallest, smartest, 

and richest OP for this bug report ;-)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=807771&group_id=5470



More information about the Python-bugs-list mailing list