Sort list of dictionaries by key (case insensitive)
Chris Rebert
clp2 at rebertia.com
Wed Jan 13 06:13:30 EST 2010
On Wed, Jan 13, 2010 at 2:41 AM, Chris Rebert <clp2 at rebertia.com> wrote:
> On Tue, Jan 12, 2010 at 11:45 PM, Nico Grubert <nicogrubert at gmail.com> wrote:
>> Hi there
>>
>> I have the following list 'mylist' that contains some dictionaries:
>>
>> mylist = [{'title':'the Fog', 'id':1},
>> {'title':'The Storm', 'id':2},
>> {'title':'the bible', 'id':3},
>> {'title':'The thunder', 'id':4}
>> ]
>
> mylist.sort(key = lambda d: d['title'])
Er, that should have been mylist.sort(key = lambda d:
d['title'].lower()) of course.
<Goes for more coffee>
Cheers,
Chris
More information about the Python-list
mailing list