let dict: [String:Int] = ["apple":5, "pear":9, "grape":1]
Run Code Online (Sandbox Code Playgroud)
如何根据Int值对字典进行排序,以便输出为:
sortedDict = ["pear":9, "apple":5, "grape":1]
Run Code Online (Sandbox Code Playgroud)
let sortedDict = sorted(dict) { $0.1 > $1.1 }
Run Code Online (Sandbox Code Playgroud)