Newbie: sort list of dictionaries

Sven Brandt no_more_spam at no_use_for.me
Tue Dec 30 07:26:27 EST 2003


Hi there,

please excuse for asking such basic questions (I am new to programming, esp. 
python).

I have a list of dictionaries. I want the elements of the list to be sorted by 
the value of a key of the dict .

Excample:
my_list=[{'title': 'foo', 'id': 5, 'text': 'some text'},
          {'title': 'bar', 'id': 3, 'text': 'my text'},
          {'title': 'bla', 'id': 6, 'text': 'any text'}, ]

my_list.sort("by the id value")

Thanx for help
Sven






More information about the Python-list mailing list