Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

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'])









[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]