python - Getting lists from subdictionaries -


i'm new python, , getting pretty excited dictionaries. let me name don't have remember field positions, , seem make more solid code. but, right i'm faced extracting lists (1,2,3,4) , (5,6,7,8) dict of dicts. ideas?? and... code heart of stochastic modeling program, need fast fast. cheers!

evnt = {'m1':{'rate':1, 'val':5 },         'm2':{'rate':2, 'val':6 },         'd1':{'rate':3, 'val':7 },         'd2':{'rate':4, 'val':8 }} 

the 1 obvious way list-comprehension, , if not fast enough may need consider different data structure.

>>> [v['rate'] v in evnt.itervalues()] [4, 3, 1, 2] 

(note: .values() python3)

and no, can't them in order (without sorting) because dict isn't ordered in first place.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -