mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 00:11:36 +08:00
8.5
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
#8.6 倒置map
|
||||
# 8.6 将 map 的键值对调
|
||||
|
||||
194
|
||||
|
||||
这里倒置是指调换key和value。如果map的值类型可以作为key且所有的value是唯一的,那么通过下面的方法可以简单的做到倒置:
|
||||
|
||||
示例 8.7 [invert_map.go](examples/chapter_8/invert_map.go)
|
||||
@@ -26,7 +29,7 @@
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
|
||||
输出结果:
|
||||
|
||||
inverted:
|
||||
|
Reference in New Issue
Block a user