Soft list based on another list

23 Views Asked by At

I need to sort a list of objects based on one of their attributes, given another ordered list with the same attribute values.

Ordered list:

['GK', 'LB', 'CB', 'CB', 'RB', 'DM', 'CM', 'CM', 'LW', 'RW', 'ST']

List that needs to be ordered for attribute position based on the above ordered list:

{'name': 'tilik', 'surname': 'nidiyeti', 'age': 18, 'position': 'CM', 'skillset': 10, 'captain': 0}
{'name': 'cawec', 'surname': 'gevojugo', 'age': 21, 'position': 'RB', 'skillset': 10, 'captain': 0}
{'name': 'jesug', 'surname': 'vazipuma', 'age': 18, 'position': 'CB', 'skillset': 10, 'captain': 0}
{'name': 'cevem', 'surname': 'puqakapo', 'age': 18, 'position': 'GK', 'skillset': 10, 'captain': 0}
{'name': 'xarac', 'surname': 'yakopuza', 'age': 18, 'position': 'ST', 'skillset': 9, 'captain': 0}
{'name': 'napic', 'surname': 'zerupihu', 'age': 19, 'position': 'CM', 'skillset': 9, 'captain': 0}
{'name': 'monow', 'surname': 'puponoho', 'age': 20, 'position': 'LB', 'skillset': 8, 'captain': 0}
{'name': 'lojol', 'surname': 'sarujavo', 'age': 20, 'position': 'CB', 'skillset': 10, 'captain': 0}
{'name': 'jegol', 'surname': 'fahovuwa', 'age': 26, 'position': 'DM', 'skillset': 8, 'captain': 0}
{'name': 'xojid', 'surname': 'secexeru', 'age': 19, 'position': 'LW', 'skillset': 10, 'captain': 1}
{'name': 'viyov', 'surname': 'bogidico', 'age': 18, 'position': 'RW', 'skillset': 8, 'captain': 0}

So after sorting the Player with position GK should be 1st, the Player with position LB should be 2nd, etc.

0

There are 0 best solutions below