I am new to python and currently trying my way out on python dictionary comprehension. I am currently trying to fetch common keys and their values from a python dictionary using dictionary comprehension. I have tried few options but it doesn't seem to fetch the desired output. Could someone kindly point me to the right direction please.
input = [
{'name': 'xxx','class':'1','grade':'A+'},
{'name': 'yyy','class':'1','grade':'A-'},
{'name': 'zzz','class':'2','grade':'B+'},
{'name': 'ooo','class':'1','grade':'C+'},
{'name': 'ppp','class':'2','grade':'C+'},
{'name': 'sss','class':'3','grade':'A+'}
]
Expected output:
output = [
{'class':'1','grade':['A+','A-','C+'],'name':['xxx','yyy','ooo']},
{'class':'2','grade':['B+','C+'],'name':['zzz','ppp']},
{'class':'3','grade':['A+'],'name':['sss']}
]