Hello all python developers, I was playing with python lists and Pandas library and am having a trouble in a list manipulation tasks. I want to merge all test_list[i][0] dictionary items into one nested list index, according to same state name at index 0 of each nested list.
Sample Input:
test_list= [['Alabama', {'Baldwin County': 182265}],
['Alabama', {'Barbour County': 27457}],
['Arkansas', {'Newton County': 8330}],
['Arkansas', {'Perry County': 10445}],
['Arkansas', {'Phillips County': 21757}],
['California', {'Madera County': 150865}],
['California', {'Marin County': 252409}],
['Colorado', {'Adams County': 441603}],
['Colorado', {'Alamosa County': 15445}],
['Colorado', {'Arapahoe County': 572003}]
]
Sample Output:
test_list1= [['Alabama', {'Baldwin County': 182265, 'Barbour County': 27457}],
['Arkansas', {'Newton County': 8330, 'Perry County': 10445, 'Phillips County': 21757}],
['California', {'Madera County': 150865, 'Marin County': 252409}],
['Colorado', {'Adams County': 441603, 'Alamosa County': 15445, 'Arapahoe County': 572003}]
]
I have tried many approaches to solve this but no success so far.I am a beginner python developer. Thanks for helping in advance.