Sort list of dictionaries by key (case insensitive)

Nico Grubert nicogrubert at gmail.com
Wed Jan 13 02:45:41 EST 2010


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?

The result should be this list:
[{'title':'the bible', 'id':3},
  {'title':'the Fog', 'id':1},
  {'title':'The Storm', 'id':2},
  {'title':'The thunder', 'id':4}
]

I am using Python 2.4.


Regards,
Nico



More information about the Python-list mailing list