Getting the minimum from a list.

Bengt Richter bokr at oz.net
Sun May 25 07:47:25 EDT 2003


On 25 May 2003 01:09:41 -0700, aeze616 at cse.unsw.edu.au (anson) wrote:

>Dear sir,
>
>   if I have something like this:
>
>data = [[(("file", 101, "function f")], 456, 80000)]
>	[(("file2", 102, "function"), 321, 90000]]
>
>how do I extra the 321 using a minimum method in python?
>
Start by writing something without syntax errors ;-)

Perhaps you meant something like

 >>> data = [
 ...     [[("file", 101, "function f")], 456, 80000],
 ...     [[("file2", 102, "function")], 321, 90000]
 ... ]

You can extract the second from last element in each sublist of data thus:

 >>> [x[-2] for x in data]
 [456, 321]

and the minimum of that result is
 >>> min([x[-2] for x in data])
 321

This might be slightly different if your corrected data syntax is different
from the above. Bear in mind that had you posted an actual experimental example
copied from a log of your interactive testing, you might have solved the problem
yourself, or someone here could help you more precisely. If you repeatedly
post uncompilable code, people will lose patience (unless you are posting
the tracebacks and asking for help understanding those). Please do your part ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list