max(s) does not what I expect it to do.

Gerrit Holl gerrit.holl at pobox.com
Sun Jun 20 14:21:21 EDT 1999


Hello all,

I have troubles with the max() function. From the python documentation:

max (s[, args...]) 
    With a single argument s, return the largest item of a non-empty sequence
    (e.g., a string, tuple or list). With more than one argument, return the
    largest of the arguments. 

So I did the following:

Python 1.5.2 (#1, Apr 18 1999, 00:16:12)  [GCC 2.7.2.3] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> list = [ ['a'], ['a', 'b'], ['a', 'b', 'c'] ]
>>> max(list)
['a', 'b', 'c']
>>> list = [ ['a', 'b', 'c'], ['a', 'b'], ['a'] ]
>>> print max(list)
['a', 'b', 'c']

It seems to return the item with the highest index, the latest item. But that
sounds weird, becuase one can also reach that with list[-1].

And than I've got another question: is there an equivalent to
string.ljust, string.rjust and string.center for lists? e.g., I've the
following list:
['a']
and I want to make it:
['a', None, None]
by doing:
['a'].ljust('None', 3)	# or something similar.

Actually, this is the thing I want to reach with the above, I've got a lists
of lists and they have to be the same lenght. Does anyone have better
algorithms than the above for that?

By the way, If you're Dutch and reply me, than please reply in Dutch.

groeten,
Gerrit.

-- 
The Dutch Linuxgames homepage:	http://linuxgames.nl.linux.org
Personal homepage:		http://www.nl.linux.org/~gerrit/

Discoverb is a python program in Dutch and English which tests the words you
learned by asking it. Homepage: http://www.nl.linux.org/~gerrit/discoverb/




More information about the Python-list mailing list