Re: [Tutor] Get max quantity

2007-06-14 Thread Kent Johnson
Brian Wisti wrote: > Hi Carlos, > > On 6/13/07, Carlos <[EMAIL PROTECTED]> wrote: >> Hello, >> >> If I have a dictionary like: >> >> inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217} >> >> How can I get the item with the largest quantity? I tried: >> >> max(inventory) >> >>

Re: [Tutor] Get max quantity

2007-06-13 Thread Brian Wisti
Hi Carlos, On 6/13/07, Carlos <[EMAIL PROTECTED]> wrote: > Hello, > > If I have a dictionary like: > > inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217} > > How can I get the item with the largest quantity? I tried: > > max(inventory) > > but got: > > 'pears' > > What I wou

Re: [Tutor] Get max quantity

2007-06-13 Thread Jason Massey
More than one way to skin a cat: import operator sort_key = operator.itemgetter(1) sorted(inventory.items(),key=sort_key)[-1] ('oranges',525) or... inventory.items() [('pears', 217), ('apples', 430), ('oranges', 525), ('bananas', 312)] count_first = [(count,fruit) for fruit,count in invent

Re: [Tutor] Get max quantity

2007-06-13 Thread Kent Johnson
Carlos wrote: > Hello, > > If I have a dictionary like: > > inventory = {'apples': 430, 'bananas': 312, 'oranges': 525, 'pears': 217} > > How can I get the item with the largest quantity? I tried: > > max(inventory) > > but got: > > 'pears' > > What I would like to get is 'oranges', at least