Skip to content
Advertisement

Sort lists of dictionaries within dictionary

EDIT:
I’m editing the whole post as it wasn’t as clear as I thougt.

I have this dictionary (list of dictionaries within a dictionary) and I need to sort it by the values of "Position" and "Team", meaning that I need to get all the values from those two keys and print them as I show below. I know how to get each value, but I don’t know how to get them and sort them.

JavaScript

I tried this piece of code, but I still can’t get it to work.

JavaScript

My actual dictionary is much bigger than this one, and I pretend to make it even bigger. I need the output to be something like:

JavaScript

In this example I only included strings, but I need to also sort similar dictionaries by integer values.

Advertisement

Answer

Extract values of dic as tuple of (Position, Team),
Concatenate them to create flattened tuple of (Position, Team) elements.
Sort them with sorted

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement