Scripting >> Python >> Examples >> Lists >> Working with list of dictionaries


## (1) Intializing a list of dictionaries
## Example we create a list of contact data, each list item is a dictionary with keys 'name' and 'age'

ContactList = [
                {
                  'name' : 'Tom',
                  'age'  : 10
                },
                {
                  'name' : 'Dick',
                  'age'  : 15
                },
                {
                  'name' : 'Mary',
                  'age'  : 20
                }
              ]






## To sort the list by one or more dictionary keys

SortedContactList = sorted(ContactList, key=lambda d: d['name'])