Re: Dictionary sorting problem

2005-09-17 Thread Bengt Richter
On 17 Sep 2005 11:01:41 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> or tell sorted what to do ;-) >> >> >>> original= { >> ... 'hello':135, >> ... 'goodbye':30, >> ... 'lucy':4, >> ... 'sky':55, >> ... 'diamonds':239843, >> ... 'yesterday':4 } >> >>> list(sorted(

Re: Dictionary sorting problem

2005-09-17 Thread Duncan Booth
Bengt Richter wrote: > or tell sorted what to do ;-) > > >>> original= { > ... 'hello':135, > ... 'goodbye':30, > ... 'lucy':4, > ... 'sky':55, > ... 'diamonds':239843, > ... 'yesterday':4 } > >>> list(sorted(original.iteritems(), None, lambda t:t[1], True)) > [('diamonds', 239843), ('hell

Re: Dictionary sorting problem

2005-09-16 Thread Bengt Richter
On Fri, 16 Sep 2005 21:42:40 +0200, Irmen de Jong <[EMAIL PROTECTED]> wrote: >JerryB wrote: >> Hi, >> I have a dictionary for counting ocurrences of strings in a document. >> The dictionary looks like this: >> >> 'hello':135 >> 'goodbye':30 >> 'lucy':4 >> 'sky':55 >> 'diamonds':239843 >> 'yesterd

Re: Dictionary sorting problem

2005-09-16 Thread Jason Mobarak
You can't sort dictionaries (as implemented by hash tables), they are unordered data types, so by definition there's no way to force an order on them. http://en.wikipedia.org/wiki/Hash_tables -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary sorting problem

2005-09-16 Thread Irmen de Jong
JerryB wrote: > Hi, > I have a dictionary for counting ocurrences of strings in a document. > The dictionary looks like this: > > 'hello':135 > 'goodbye':30 > 'lucy':4 > 'sky':55 > 'diamonds':239843 > 'yesterday':4 > > I want to print the dictionary so I see most common words first: > > 'diamond

Dictionary sorting problem

2005-09-16 Thread JerryB
Hi, I have a dictionary for counting ocurrences of strings in a document. The dictionary looks like this: 'hello':135 'goodbye':30 'lucy':4 'sky':55 'diamonds':239843 'yesterday':4 I want to print the dictionary so I see most common words first: 'diamonds':239843 'hello':135 'sky':55 'goodbye':3