Print from List Python -


suppose list (dictionary?) given as:

a = [{ 'a':'z', 'b':'x', 'c':'w', 'd':'v'}, {{ 'a':'f', 'b':'g', 'c':'h', 'd':'i'}, [...]] 

i tried access elements follows:

print values[0].get(2)  

and got none

a bit unclear, looking this?

in [41]: = [{ 'a':'z', 'b':'x', 'c':'w', 'd':'v'}, { 'a':'f', 'b':'g', 'c':'h', 'd':'i'}]  in [42]: a[0].get('a') out[42]: 'z' 

...or this?

in [50]: a[0].values() out[50]: ['z', 'w', 'x', 'v'] 

...or using provided data:

in [47]: data = {'style': '-', 'subcat': '-', 'name': 'eurodollar futures', 'oi': '9,774,883', 'floor': 'ed', 'url': '/trading/interest-rates/stir/eurodollar_contract_specifications.html', 'clearing': 'ed', 'cpc': 'ed', 'venues': 'globex floor clearport ', 'cat': '-', 'vol': '2,026,353', 'globex': 'ge', 'group': 'interest rate', 'tags': '-', 'cleared': 'futures', 'id': 1, 'exch': 'cme', 'subgroup': 'stirs'}  in [48]: data.get('name') out[48]: 'eurodollar futures' 

you can loop on dictionary:

in [52]: k,v in a[0].iteritems():    ....:     print k, v    ....:      z c w b x d v 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -