Re: [Tutor] how to sort a dictionary by values

2007-08-08 Thread shawn bright
sorry all, i did mean greatest to least, thanks for all the help here shawn On 8/8/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > > Tiger12506 wrote: > >> Just curious: Is there a reason to use __getitem__() over itemgetter > (used > >> in the example in my reply)? > > > > __getitem__ is a method b

Re: [Tutor] how to sort a dictionary by values

2007-08-08 Thread Kent Johnson
Tiger12506 wrote: >> Just curious: Is there a reason to use __getitem__() over itemgetter (used >> in the example in my reply)? > > __getitem__ is a method builtin to a dict object. itemgetter 1) has to be > imported 2) is more generically used, therefore probably using a more > generic/slower

Re: [Tutor] how to sort a dictionary by values

2007-08-08 Thread Kent Johnson
wormwood_3 wrote: >>> You can use d.__getitem__ as the key function for a sort of the keys. >>> __getitem__() is the special method that is called for indexing a >>> dictionary (or a list). > > Just curious: Is there a reason to use __getitem__() over itemgetter > (used in the example in my repl

Re: [Tutor] how to sort a dictionary by values

2007-08-07 Thread Luke Paireepinart
wormwood_3 wrote: >>> You can use d.__getitem__ as the key function for a sort of the keys. >>> __getitem__() is the special method that is called for indexing a >>> dictionary (or a list). >>> > > Just curious: Is there a reason to use __getitem__() over itemgetter (used in > the example

Re: [Tutor] how to sort a dictionary by values

2007-08-07 Thread Tiger12506
> Just curious: Is there a reason to use __getitem__() over itemgetter (used > in the example in my reply)? __getitem__ is a method builtin to a dict object. itemgetter 1) has to be imported 2) is more generically used, therefore probably using a more generic/slower algorithm JS

Re: [Tutor] how to sort a dictionary by values

2007-08-07 Thread wormwood_3
>>You can use d.__getitem__ as the key function for a sort of the keys. >>__getitem__() is the special method that is called for indexing a >>dictionary (or a list). Just curious: Is there a reason to use __getitem__() over itemgetter (used in the example in my reply)? >>In [24]: d = {'a':21.3

Re: [Tutor] how to sort a dictionary by values

2007-08-07 Thread Kent Johnson
shawn bright wrote: > hello there all, > i am wondering how to sort a dictionary that i have by values. > And i also need to sort them from greatest to least > like if i have a dictionary > > d = {'a':21.3, 'b':32.8, 'c': 12.92} > > how could i sort these from least to greatest > so that the orde

Re: [Tutor] how to sort a dictionary by values

2007-08-07 Thread wormwood_3
>>hello there all, >>i am wondering how to sort a dictionary that i have by values. >>And i also need to sort them from greatest to least >>like if i have a dictionary >> >>d = {'a':21.3, 'b':32.8, 'c': 12.92} >> >>how could i sort these from least to greatest >>so that the order would turn out >>b

[Tutor] how to sort a dictionary by values

2007-08-07 Thread shawn bright
hello there all, i am wondering how to sort a dictionary that i have by values. And i also need to sort them from greatest to least like if i have a dictionary d = {'a':21.3, 'b':32.8, 'c': 12.92} how could i sort these from least to greatest so that the order would turn out b,a,c thanks shawn _