Golang container/list.List.Remove() function example
package container/list
Remove removes element (e) from list if (e) is an element of the list. It returns the element value e.Value.
Golang container/list.List.Remove() function usage example
package main
import (
"container/list"
"fmt"
)
func main() {
alist := list.New()
alist.PushFront("a")
alist.PushFront("b")
alist.PushFront("c")
alist.PushFront("d")
fmt.Println("Elements in List : ")
for e := alist.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value) // print out the elements
}
elementFromAList := alist.Front()
removed := alist.Remove(elementFromAList)
fmt.Printf("Removed element [ %s ] from list\n", removed)
fmt.Println("List After Removal : ")
for e := alist.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value) // print out the elements
}
}
Output :
Elements in List :
d
c
b
a
Removed element [ d ] from list
List After Removal :
c
b
a
Reference :
Advertisement
Something interesting
Tutorials
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+14k Golang : Compress and decompress file with compress/flate example
+30.4k Golang : How to redirect to new page with net/http?
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+6.2k Golang : Calculate US Dollar Index (DXY)
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+4.7k Chrome : How to block socketloop.com links in Google SERP?
+10.8k Golang : Natural string sorting example
+15k Golang : package is not in GOROOT during compilation
+52.6k Golang : How to get struct field and value by name
+18.2k Golang : Get command line arguments
+13.3k Golang : Linear algebra and matrix calculation example