[英]get values of 2nd and 3rd element of a result set using the value of the 1st element
[英][Kotlin/Python]Can I merge two maps so the key of the 3rd map is the value of the 1st map and the value of the 3rd map is the value of the 2nd map?
假設我有這些變量,
val mapOfNodesToCoordinates = mutableMapOf<String, String>()
9600030594=“1.3289149_103.9296551”,9600040000=“1.3279014_103.928449”
val mapOfWaysToRoutes = mutableMapOf<String, List<String>>()
-122174 = [“9600030594”,“9600040000”]
我想要第三張地圖,它將是:
-122174 = [“1.3289149_103.9296551”,“1.3279014_103.928449”]
這可以在 kotlin 或 python 中完成嗎?
在 Kotlin 中,您可以通過以下方式實現:
val result = mapOfWaysToRoutes.mapValues { (_, values) -> values.map { mapOfNodesToCoordinates[it] } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.