import ( "container/list" ) func main() { l := list.New() l.PushBack(1) l.PushBack(2) l.PushBack(3) // remove element with value 2 for e := l.Front(); e != nil; e = e.Next() { if e.Value == 2 { l.Remove(e) } } }
import ( "container/list" ) type entry struct { key string val string } func main() { l := list.New() l.PushBack(&entry{key: "foo", val: "bar"}) l.PushBack(&entry{key: "hello", val: "world"}) // remove element with key "foo" for e := l.Front(); e != nil; e = e.Next() { if e.Value.(*entry).key == "foo" { l.Remove(e) } } }In this example, we create a new list of `entry` structs which have a `key` and `val` field. We add two entries to the list and then remove the one with a `key` of "foo" using the `Remove()` method. The package library for these examples is `container/list`.