Given an array of float64 (or any other thing), I would like to build a set
similar to the set we find in python. What is the best approach to designing such a data structure?
So far I managed to build a set using a map but it seems awkward to repurpose map to build a set.
package main
import (
"fmt"
"sort"
)
func main() {
var scores = []float64{
12.0, 6.0, 19.0, 20.0, 2.0, 8.0, 20.0,
}
set := make(map[float64]bool)
for _, t := range scores {
set[t] = true
}
unk := make([]float64, 0, len(set))
for t := range set {
unk = append(unk, t)
}
sort.Float64s(unk)
fmt.Println(unk)
}
Will produce
[2 6 8 12 19 20]