Let us say, we have a Map that contains,
As 'Key' and 'Value' pair.
Now, if you want to remove the entries from a 'Map', 'pop()', 'popitem()', 'clear()' Function and 'del' keyword can be used.
Let us look at the 'pop()' Function first.
The 'delete()' Function can be used to remove an item from the Map.
Let us say, we want to remove the entry where the 'Key' is 'Pune' and 'Value' is 'Is a City'.
package main import "fmt" func main() { x := map[string]string { "Pune" : "Is a City", "John": "Is a Name", "Go": "Is a Language"} delete(x, "Pune") for i,j := range x { fmt.Println("The value for the key ",i," is ",j) } }
So, in the above code we have created a 'Map' using braces '{}' and 'Key' and 'Value' pairs.
x := map[string]string { "Pune" : "Is a City", "John": "Is a Name", "Go": "Is a Language"}
And initialised to the variable 'x'.
Now, we are supposed to delete the value of the 'Key', 'Pune'.
So, we have used the 'delete()' Function to delete it.
And the entry for the 'Key' 'Pune' is deleted for the 'Map'.
And we get the below output,