[Tutor] When max() doesn't work as expected

Tony Cappellini cappy2112 at gmail.com
Fri Dec 4 02:08:47 CET 2009


I have a list of 2300 strings.

When I call max() on the list, it returned an item with 37 characters. I am
only passing 1 argument to max().
I know for a fact that the largest item has 57 characters, and when I called
mylist.index('my_57_character_string') the index was found.

Printing len(mylist[index]) does indeed return 57 characters.

What are the assumptions when calling max on a list of strings?
Does the list need to be sorted? In my case, the list is sorted.

Does max have any undocumented limitations I'm not aware of?

2.1 Built-in Functions  *max*( iterable[, args...][key]) With a single
argument iterable, return the largest item of a non-empty iterable (such as
a string, tuple or list). With more than one argument, return the largest of
the arguments.

The optional key argument specifies a one-argument ordering function like
that used for list.sort(). The key argument, if supplied, must be in keyword
form (for example, "max(a,b,c,key=func)"). Changed in version 2.5: Added
support for the optional key argument.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091203/1952940e/attachment.htm>


More information about the Tutor mailing list