max value in list
Peter Otten
__peter__ at web.de
Wed May 12 16:39:09 EDT 2004
C GIllespie wrote:
> I have a few lists. What's the best way of finding the maximum number of
> all the lists.
>
> For example,
>
> [2,3,4],[1,2,3],[4,7]
>
> The max is 7.
For arbitrarily nested sequences:
>>> def rmax(seq):
... try:
... return max(map(rmax, seq))
... except TypeError:
... return seq
...
>>> rmax(1)
1
>>> rmax([1,2])
2
>>> rmax([[1,2], [3,4]])
4
>>> rmax([[1,2], [3,44], 5, [6]])
44
>>> rmax([[1,2], [[3,44], 5, [6]]])
44
>>>
Peter
More information about the Python-list
mailing list