Re: Dictionary : items()

2009-01-22 Thread Benjamin
On Jan 22, 2:53 am, Paul Rubin wrote: > Steven D'Aprano writes: > > That is better written as: > > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) > > In Python 2.x, I prefer the style > >   l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) >

Re: Dictionary : items()

2009-01-22 Thread Paul Rubin
Steven D'Aprano writes: > That is better written as: > l = sorted(abcd.items(), key=lambda x:(x[1].lower(), x[0])) In Python 2.x, I prefer the style l = sorted(abcd.iteritems(), key=lambda (k,v): (v.lower(), k)) but Python 3.0 breaks the tuple unpacking per some PEP. -- http://mail.python.org

Re: Dictionary : items()

2009-01-22 Thread Steven D'Aprano
On Wed, 21 Jan 2009 23:02:11 -0800, koranthala wrote: > Hi, >Dictionary has the items method which returns the value as a list > of tuples. >I was wondering whether it would be a good idea to have an extra > parameter - sort - to allow the tuples to be sorted as the desire of > users. >

Re: Dictionary : items()

2009-01-21 Thread Terry Reedy
koranthala wrote: Hi, Dictionary has the items method which returns the value as a list of tuples. I was wondering whether it would be a good idea to have an extra parameter - sort - to allow the tuples to be sorted as the desire of users. Currently what I do is: class SDict(dict):