create a map with a key of type complex in go

In Go, we can create a map with a key of type complex using the map keyword and the complex128 type as the key. Here's an example:

main.go
package main

import (
    "fmt"
)

func main() {
    m := make(map[complex128]int)
    c1 := complex(2, 3)
    c2 := complex(4, 5)
    m[c1] = 10
    m[c2] = 20
    fmt.Println(m)
}
183 chars
15 lines

In this example, we create a new map by using make and specifying the key as complex128. We then create two complex numbers c1 and c2 and use them to set values in the map. We can then print out the entire map using fmt.Println(m).

gistlibby LogSnag