4
我对下面的列表:生成地图[字符串,列表[字符串]从列表[(字符串,字符串)]
List(("US","New York"),("England","London"),("US","Los Angeles"),("England","Manchester"),("US","Washington"))
我需要生成一个Map[Country, List[Cities]]
:
Map("US" -> List("New York", "Los Angeles", "Washington"), "England" -> List("London", "Manchester"))
如果我直接使用toMap()
,则会删除具有相同键的值的问题。使用GROUPBY
list.groupBy(el => el).map(el => el._1 -> ?)