Hi ppl , hope this Q is not overlapping , searched long before asking.
i wanted to create a dict when the value can be any thing , which is working , but the last 3 lines doesn’t
func main() {
a := make(map[string]interface{})
a["start"] = map[string]interface{}{
"hello": 2,
"world": 3,
"here": map[string]interface{}{
"test1": 123,
"test2": "dsd",
"level3": map[string]interface{}{
"ha1": "kuku",
"ha2": "nana",
},
},
}
fmt.Println(a)
a["start"]["here"]["level3"]["222"] = "string1" **// why i got an error ?**
a["start"]["here"]["level3"]["444"] = make(map[string]interface{}) **// why i get an error ?**
delete(a["start"]["here"], "world") **// why i get an error ?**
}
The Q is the last 3 lines , will appreciate as much more details as possible.
also i would like to add this little block here :
dict2 := make(map[interface{}]interface{})
dict2[1] = "wow"
dict2["2"] = "wawa"
dict2[3] = make(map[interface{}]interface{}) // **this is not working as well**
dict2[3]["test3"] = "nice" // **this is not working as well**
this is same family questions so i have decided to put it here , guess i am missing some go concept.
and there the Q about the last 2 lines.
@NobbZ - i am not a go expert, and even tho i have read what assert is and why should i use it
still don’t see how can it help me, so please be more informative with the answer you give , like
an example that relates to my code would be great.
Thank you @NobbZ , very appriciated , but i wonder how do i get to a point that i can work with dictionaries in go in the same comfort that i work with them in python.
is it possible?
@NobbZ - can u please give an example of how to work with monomorphic dict as well(that u have
mentione , let’s say :
dict1 := map{string}map{} , and now i want that each level will filled with strings as keys
and the value of the key will be map which will hold a key ( string ) and value of another map
let’s say 4 level deep ( may be less as long the example is clear ), example (yamelish):