python - Reconstructing list from JSON using itertools -


is possible reconstruct list(snippet of result):

[     [         {             "counthigh": 3,             "brgy_locat": "barangay 2",             "municipali": "cabadbaran city"         }     ],     [         {             "brgy_locat": "barangay 2",             "countmedium": 22,             "municipali": "cabadbaran city"         }     ],     [         {             "brgy_locat": "barangay 2",             "countlow": 13,             "municipali": "cabadbaran city"         }     ] ] 

into this?

[     [         {             "counthigh": 3,             "countmedium": 22,             "countlow": 13,             "brgy_locat": "barangay 2",             "municipali": "cabadbaran city"         }     ] ] 

the list output of query in can't change it. using django.

edit: let's have other dict of same brgy_locat , municipali counthigh: 5 should add both of values. reconstructed list should counthigh:8. result given snippet.

using chain.from_iterable:

>>> itertools import chain >>> result = {} >>> d in chain.from_iterable(a): ...     result.update(d) ... >>> result {'municipali': 'cabadbaran city', 'counthigh': 3, 'brgy_locat': 'barangay 2', 'countmedium': 22, 'countlow': 13} 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -