Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maps - deleting data

Tags:

dictionary

go

How does one delete data from a map in Go? For example, having

m := map[string]string{ "key1":"val1", "key2":"val2" };

I want to make m drop the "key1" without copying the entire map by iterating over its keys (which could get big in some uses). Is it enough to assign a nil value to "key1", or will that still keep the key in the map structure with an assigned value of nil? That is, if I later iterate over the keys of the map, will "key1" appear?

like image 331
ThePiachu Avatar asked Feb 10 '12 19:02

ThePiachu


People also ask

What happens if I clear data on Google Maps?

Clear app data Google Maps stores data like shared locations, saved locations, and map tiles on your phone or tablet. Clearing this data will do the following things: Delete cache (including search suggestions, direction searches, map tiles, and activity page content stored on your device)

Can I clear data on maps?

Delete all places from your historyand sign in. Maps history. Delete activity by. ​To delete by date: Under the "Delete by date" section choose a date range.

How do you clear data from maps on iPhone?

Go to Settings > Privacy > Location Services > System Services, then tap Significant Locations. Tap Clear History. This action clears all your significant locations on any devices that are signed in with the same Apple ID.


1 Answers

Deletion of map elements

The built-in function delete removes the element with key k from a map m.

delete(m, k)  // remove element m[k] from map m 

For example,

package main  import "fmt"  func main() {     m := map[string]string{"key1": "val1", "key2": "val2"}     fmt.Println(m)     delete(m, "key1")     fmt.Println(m) } 

Output:

map[key1:val1 key2:val2] map[key2:val2] 
like image 153
peterSO Avatar answered Sep 28 '22 08:09

peterSO