gpt4 book ai didi

html - 单个键在 scala 的 Map 中包含多个值

转载 作者:搜寻专家 更新时间:2023-10-31 23:20:54 24 4
gpt4 key购买 nike

我是 scala 的新手。我想为所有包含 PINCODE 作为键和所有其他字段作为值的波纹管数据创建映射。

<!DOCTYPE html>
<html>
<body>
<table border="1">
<tr>
<th>PINCODE</th>
<th>Locality</th>
<th>PO_TYPE</th>
<th>TALUK</th>
<th>DISTRICT</th>
</tr>
<tr>
<td>500001</td>
<td>Hyderabad G.P.O.</td>
<td>Branch Post Office</td>
<td>Hyderabad</td>
<td>HYDERABAD</td>
</tr>
<tr>
<td>500001</td>
<td>Gandhi Bhawan</td>
<td>Branch Post Office</td>
<td>Nampally</td>
<td>HYDERABAD</td>
</tr>
<tr>
<td>500001</td>
<td>Hindi Bhawan</td>
<td>Branch Post Office</td>
<td>Nampally</td>
<td>HYDERABAD</td>
</tr>
<tr>
<td>500002</td>
<td>Hyderabad Jubilee</td>
<td>Branch Post Office</td>
<td>HYDERABAD</td>
<td>HYDERABAD</td>
</tr>
<tr>
<td>500002</td>
<td>Moghalpura Branch</td>
<td>Post Office</td>
<td>HYDERABAD</td>
<td>HYDERABAD</td>
</tr>
</table>

</body>
</html>

例如:(输出如下)

(500001, (Hyderabad G.P.O.,Branch Post Office,Hyderabad,HYDERABAD), (Gandhi Bhawan,Branch Post Office,Nampally,HYDERABAD), (Hindi Bhawan,Branch Post Office,Nampally,HYDERABAD))

(500002 ,(Hyderabad Jubilee,Branch Post Office,HYDERABAD,HYDERABAD), (Moghalpura Branch,Post Office,HYDERABAD,HYDERABAD))

提前致谢

最佳答案

你想要MultiMap , 例子:

  val mm = new mutable.HashMap[Int, mutable.Set[String]] with mutable.MultiMap[Int, String]
mm.addBinding(500001, "a")
mm.addBinding(500003, "b")
mm.addBinding(500001, "c")
val l = mm.getOrElse(500001, List())
println(l)

对于List的值类型,可以设置MultiMap的值类型为:List[String],如:

  val mm = new mutable.HashMap[Int, mutable.Set[List[String]]] with mutable.MultiMap[Int, List[String]]
mm.addBinding(500001, List("a", "b"))
mm.addBinding(500003, List("b", "c"))
mm.addBinding(500001, List("c", "D"))
val l = mm.getOrElse(500001, Set())
println(l)

输出:

  Set(List(e, f), List(a, b))

关于html - 单个键在 scala 的 Map 中包含多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41034077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com