Sort an Array by multiple Dictionary values

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Artorias93

Hi, I need to sort an Array of Dictionaries, in order by multiple parameters:

Array = [
{“Score”: int1, “Years”: int1, “Month”: int1, “Situation”: “String2”},
{“Score”: int2, “Years”: int2, “Month”: int2, “Situation”: “String1”},
{“Score”: int3, “Years”: int3, “Month”: int3, “Situation”: “String1”},

{“Score”: intN, “Years”: intN, “Month”: intN, “Situation”: “String3”}

This is my Array… I need to order by “Score”, at the same “Score” by “Years”, at the same “Score” and “Years” by “Month”, at the same “Score”, “Years” and “Month” by “Situation” (“” previous the != “”)…

Someone can help me?

:bust_in_silhouette: Reply From: klaas

yoi can use your own custome sort function.

Read about it here:

For that you have to provide a function that compares two items and return true or false depending on if item A should be “on top” of item B.