getting all values from a dict key
hei folks,
i'm new to dictionaries and i've got one structured as following:
{
"animals" : {
"monkey" : 21,
"bear" : 22
}
,
"cars" : {
"fiat" : 23,
"opel" : 24
}
}
i'd like to return all values from the key "animals" (so basically "monkey 21" and "bear 22"). is it possible? banging and itering the dict only spits out its name – sending a "get animals" doesn't work, either.
thanks!
Hi !
have u checked Dict help : hierarchy tab & array tab ?
hei there,
yes i have. unfortunately it doesn't tell me how to get *all* keys from a certain directory. as for my example - "animals" being the top directory, i'd like to dump all it's keys and their values, but (get animals::) and the like does not work.
right !
your keys are dictionaries . so u have to refer to them . u should check dict.unpack and dict.iter it will help u to strip the keys !
or directly
oh great! that was pretty easy! - thanks so much.
Very helpful, much appreciated!
Thaaanks
Is there no way to extract just the keys from sub-dictionaries? Having to iterate over everything in your sub-dictionaries and then get your keys seems fairly inefficient, especially as each item in my dictionary is a long list.
“get” the sub-dictionary, put it into a [dict] object and call “getkeys”?
No worries, just tried Do.While's example again and it's perfect.