sorting - How can I sort a dictionary by key in Scala? -


it easy sort map keys or values in python (this question example).

i same thing in scala, lets have dictionary like:

val a= map(0 -> 1.0, 3 -> 5.0,2->7.0) 

i list of tuples correspond sorted map keys:

val a_sorted= list((0,1.0),(2,7.0),(3,5.0)) 

thanks!

map(0 -> 1.0, 3 -> 5.0,2->7.0).tolist.sortby(_._1)  res1: list[(int, double)] = list((0,1.0), (2,7.0), (3,5.0)) 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -