I have a dictionary that stores countries and offices I need to sort them by Country then by office locations. I manage to sort them by Country by doing this;
sorted_list = [[id, desc] for id, desc in sorted(locations.items(), key=lambda item: (item[1]['name']))
however when I tried to do items[1]['cities']['names'] it didnt work because obviously index is string not integer.
(TypeError: list indices must be integers or slices, not str )
What I need to do is Sort By Country first and Sort By cities inside
Expected Output:
Austria -> Gramatneusiedl / Vienna, Home Office, Lenzing, Schoerfling, Weissenstein
Belgium -> Antwerp, Brussels, Home Office, Oostende
Initial Input:
 locations = '2248': {
            'name': 'Austria',
            'cities': [{
                'OptionId': 2289,
                'name': 'Gramatneusiedl / Vienna'
            }, {
                'OptionId': 2290,
                'name': 'Lenzing'
            }, {
                'OptionId': 2291,
                'name': 'Schoerfling'
            }, {
                'OptionId': 2292,
                'name': 'Weissenstein'
            }, {
                'OptionId': 2293,
                'name': 'Home Office'
            }]
        },
    '2249': {
                'name': 'Belgium',
                'cities': [{
                    'OptionId': 9367,
                    'name': 'Oostende'
                }, {
                    'OptionId': 2294,
                    'name': 'Antwerp'
                }, {
                    'OptionId': 2295,
                    'name': 'Brussels'
                }, {
                    'OptionId': 2296,
                    'name': 'Home Office'
                }]
 
     
    