How to ascending sort dictionary with integer arrays in Swift

1 Answer

0 votes
var dic = ["swift": [5, 7, 0, 1],
           "c++": [8, 9, 4, 3],
           "python": [3, 2, 0, 5]]

print(dic)

for key in dic.keys {
    dic[key]?.sort(by: <)
}

print(dic)




/*
run:

["swift": [5, 7, 0, 1], "c++": [8, 9, 4, 3], "python": [3, 2, 0, 5]]
["swift": [0, 1, 5, 7], "c++": [3, 4, 8, 9], "python": [0, 2, 3, 5]]

*/

 



answered Sep 19, 2020 by avibootz
...