Write Python3 code to demonstrate working of Segregating key's value in list of dictionaries Using generator expression


Topic: Write Python3 code to demonstrate working of Segregating key's value in list of dictionaries Using generator expression

Solution

test_list = [{'gfg' : 1, 'best' : 2}, {'gfg' : 4, 'best': 5}] 
print("The original list : " + str(test_list)) 
res = [tuple(sub["gfg"] for sub in test_list), 
    tuple(sub["best"] for sub in test_list)] 
print("Segregated values of keys are : " + str(res)) 



List all Python Programs