Feb-02-2017, 05:52 PM
A less elegant solution using nested dict that can be used with any python version:
item_dict = { '1': { 'Item': 'Widgets', 'Unit': 'each', 'QtyPerUnit': 1, 'PricePerUnit': 14.25 }, '2': { 'Item': 'Wigs', 'Color': ['red', 'brown', 'white'], 'Unit': 'each', 'QtyPerUnit': 1, 'PricePerUnit': 5.25 }, '3': { 'Item': 'fountain drink', 'Size': ['small', 'medium', 'large'], 'Unit': 'Ounces', 'QtyPerUnit': 16, 'PricePerUnit': 1.95 } } merchandise = list(item_dict.keys()) merchandise.sort() print('merchandise: {}'.format(merchandise)) print('item_dict 1: {}'.format(item_dict['1']))results:
Output:merchandise: ['1', '2', '3']
item_dict 1: {'PricePerUnit': 14.25, 'Item': 'Widgets', 'QtyPerUnit': 1, 'Unit': 'each'}