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
Post a Comment