Here is a dictionary
dictionary = {'Happy':['SMILE','LAUGH','BEAMING'],
'Sad':['FROWN','CRY','TEARS'],
'Indifferent':['NEUTRAL','BLAND', 'MEH']}
I am trying to change the values in the entire dictionary such that SMILE becomes Smile, LAUGH becomes Laugh etc.
This is what I’m attempted
{str(k).upper():str(v).upper() for k,v in dictionary.values()}
But the result of this is capitalizing the keys and does noting to the values.
>Solution :
Try the below
d = {'Happy':['SMILE','LAUGH','BEAMING'],
'Sad':['FROWN','CRY','TEARS'],
'Indifferent':['NEUTRAL','BLAND', 'MEH']}
d = {k:[x.capitalize() for x in v] for k,v in d.items()}
print(d)
output
{'Happy': ['Smile', 'Laugh', 'Beaming'], 'Sad': ['Frown', 'Cry', 'Tears'], 'Indifferent': ['Neutral', 'Bland', 'Meh']}