HI I am fairly new to scala programming.
(嗨,我对scala编程还很陌生。)
I want to know is there a way to rename the duplicate keys of map. (我想知道是否有一种方法可以重命名map的重复键。)
Suppose if I have a scala map here like
(假设我在这里有一个斯卡拉地图)
("a"->1,"b"->2,"c"->3,"d"->4,"a"->5,"c"->6,"e"->7,"a"->8)
((“ a”-> 1,“ b”-> 2,“ c”-> 3,“ d”-> 4,“ a”-> 5,“ c”-> 6,“ e”-> 7, “ a”-> 8))
I want the output in below format.The map should look like
(我想要以下格式的输出。地图应该看起来像)
("a_1"->1,"b"->2,"c_1"->3,"d"->4,"a_2"->5,"c_2"->6,"e"->7,"a_3"->8)
((“ a_1”-> 1,“ b”-> 2,“ c_1”-> 3,“ d”-> 4,“ a_2”-> 5,“ c_2”-> 6,“ e”-> 7, “ a_3”-> 8))
I just want to kind of assign a count system for each duplicate key occurrance.
(我只想为每个重复的键出现分配一个计数系统。)
So far I have been able to write a code which will give the no of occurance for a duplicate key.
(到目前为止,我已经能够编写代码,避免重复密钥的出现。)
var seq=map.toSeq
var cnt=seq.groupBy(_._1).mapValues(_.length)`
ask by Nils translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…