I don't want to sort a collection of lists according to a selected list but rather, I have a dictionary which contains lists. I wish to display the dictionary after sorting the lists according to a chosen key.
names = ["John", "Mary", "Frank", "Sandra"]
countries= ["France", "Spain", "Holland", "America"]
travel_days = [23, 14, 52, 21]
places_travelled = [3, 7, 6, 12]
dictionaryIs = {"Names": names, "Countries":countries, "Days":travel_days, "Places", places_travelled}
So from these entries, John is in France, has been there for 23 days and has seen 3 places. I am trying to do ordered searches by ascending and descending order, such as "Who has travelled the longest time? Who has travelled to the fewest places?"
sorted(x.values())
This sorted method on sorts only "John", "France", 23, 3. With the other lists following the same order
sorted(x.items(), key = lambda e:e[1][2])
This method sorts "Mary", "Spain", 14, 7. Though I'm not sure how. But isn't what I'm looking for.
After sorting travel_days to look like [52, 34, 21, 14], the other list should match the reordering. How do you order a dictionary of lists by key values ascending and descending order?