max value in list

C

C GIllespie

Dear all,

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.

Thanks

Colin
 
J

Jean Brouwers

[[ This message was both posted and mailed: see
the "To," "Cc," and "Newsgroups" headers for details. ]]


What about:

m = max([max(i) for i in (list1, list2, list3, etc...)])

Example:
max([max(i) for i in ([2,3,4], [1,2,3], [4,7])])
7

/Jean Brouwers
ProphICy Semiconductor, Inc.


C GIllespie said:
Dear all,

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.

Thanks

Colin
 
P

Peter Abel

C GIllespie said:
Dear all,

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.

Thanks

Colin
l=[[2, 3, 4], [1, 2, 9], [4, 7]]
max(map(max,l)) 9
l=[[2, 3, 4], [1, 2, 9],[12], [4, 7]]
max(map(max,l)) 12

Regards
Peter
 
P

Peter Otten

C said:
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:
.... 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top