I have some dictionaries of dictionaries, like this:
a['b']['c']['d']['answer'] = answer1
a['b']['c']['e']['answer'] = answer2
a['b']['c']['f']['answer'] = answer3
....
a['b']['c']['d']['conf'] = conf1
a['b']['c']['e']['conf'] = conf2
a['b']['c']['f']['conf'] = conf3
Is there a fast way to get a list of values of all answers for all elements at the third level (d,e,f)?
Specifically I'd like to know if there's any mechanism implementing a wildcard (e.g., a['b']['c']['*']['answer'].values()
update The fastest way I've found till now is:
[x['answer'] for x in a['b']['c'].values()]
updateis the best way to do it.dictin python is implemented as a hash-table. It actually doesn't know anything about the contents of itskeys, just their hash value. Therefore there'd be no way to sensicaly implement a wildcard, other than how you just did. Or, to put it another way,values()essentially already is the equivalent of'*'as a key (in the regex sense), and the rest of what you're trying to do is just list combinatorics. - aruisdanteitervaluesinstead ofvalues. The first returns a lazy-evaluated generator, whereas the second actually allocates a list. Python 3 turnedvaluesintoitervaluesand makes you dolist(dict.values())to get a list back. - aruisdante