Let's see an example to sort a list of employee dictionaries by two keys: name and salary using sort() function. Rather than creating new dicts, which is really the only way to change the key order, you should fix where the dictionaries are created to either use collections.OrderedDict or if you are using 3.6 or later, just put the dictionaries in the right order to begin with. We can call this method on our addressbook as below: addresskeys addressbook.keys () print (addresskeys) dictkeys ( 'Alicia Johnson', 'Jerry Smith', 'Michael Jonas') The output returned above.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |