Sort list of dictionaries by key (case insensitive)

Florian Diesch diesch at spamfence.net
Wed Jan 13 06:11:08 EST 2010


Nico Grubert <nicogrubert at gmail.com> writes:

> 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}
>          ]
>
> How I can sort (case insensitive) the list by the dictioary's 'title' key?

mylist.sort(key=lambda x: x['title'].lower())



   Florian
-- 
<http://www.florian-diesch.de/software/easygconf/>



More information about the Python-list mailing list