473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

max value in list

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
Jul 18 '05 #1
6 2345
[[ 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.
In article <c7**********@ucsnew1.ncl.ac.uk>, C GIllespie
<cs******@hotmail.com> wrote:
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

Jul 18 '05 #2

"C GIllespie" <cs******@hotmail.com> wrote in message
news:c7**********@ucsnew1.ncl.ac.uk...
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.


Sidestepping 'best' which may depend on context, a general 'good' way is
lists = [2,3,4],[1,2,3],[4,7]
max([max(l) for l in lists])

7

Terry J. Reedy


Jul 18 '05 #3
"C GIllespie" <cs******@hotmail.com> wrote in message news:<c7**********@ucsnew1.ncl.ac.uk>...
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
Jul 18 '05 #4
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

Jul 18 '05 #5
"Terry Reedy" <tj*****@udel.edu> wrote in
news:ma**************************************@pyth on.org:
Sidestepping 'best' which may depend on context, a general 'good' way is
lists = [2,3,4],[1,2,3],[4,7]
max([max(l) for l in lists]) 7


Without any claims to better or worse, here is another option:
l = [2,3,4],[1,2,3],[4,7]
l ([2, 3, 4], [1, 2, 3], [4, 7]) max(itertools.chain(*l)) 7

Jul 18 '05 #6
Dear All,

Thanks for all the responses.

Very helpful (again)

Colin

Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: ago | last post by:
Is it possible to have a default value associated python objects? I.e. to flag an attribute in such a way that the assignment operator for the object returns the default attribute instead of the...
6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
4
by: Martyn Fewtrell | last post by:
I want to update a database record with a number of fields - doesn't sound to difficult at this stage! I have a system to select the correct record from the database and load the data into a...
2
by: Martin Ortiz | last post by:
Ugh.... All classes are copy by reference, even if you use "ByVal" and NOT "ByRef" it's still a copy by reference. Of course, as a consequence, if you change any values of the object you passed...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
3
by: imrantbd | last post by:
This is my first problem.Please help me. I have the following code: <head> <script language="JavaScript"> function addSrcToDestList() { destList1 = window.document.forms.destList; srcList...
9
by: Johnny Jörgensen | last post by:
Hi y'all I've got a custom control that is inherited from a normal TextBox. To that, I've added a new property that I call "Units", Which is a collection class containing members of a "Unit"...
0
by: Amar | last post by:
Hi, I have a generic list with a some objects of a particular class in it. I have implemented a IComparer for the the class and pass it to the List. The list.sort method works fine when the value...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.