package main import ( "fmt" "maps" ) func delete(k string, v int) bool { return v%2 != 0 } func equal(v1 int, v2 float64) bool { return float64(v1) == v2 } func main() { m := map[string]int{ "one": 1, "two": 2, "three": 3, "four": 4, } fmt.Printf("%#v\n", m) maps.DeleteFunc(m, delete) fmt.Printf("%#v\n", m) n := maps.Clone(m) if maps.Equal(m, n) { fmt.Println(("Equal!")) } else { fmt.Println("Not equal!") } n["three"] = 3 n["two"] = 22 fmt.Println("Before n:", n, "m:", m) maps.Copy(m, n) fmt.Println("After n:", n, "m:", m) }
zzh@ZZHPC:/zdata/Github/ztest$ go run main.go map[string]int{"four":4, "one":1, "three":3, "two":2} map[string]int{"four":4, "two":2} Equal! Before n: map[four:4 three:3 two:22] m: map[four:4 two:2] After n: map[four:4 three:3 two:22] m: map[four:4 three:3 two:22]
标签:map,fmt,two,three,four,maps,Zgo From: https://www.cnblogs.com/zhangzhihui/p/18241794