I have the following dictionary:
dict = {12:'Apples', 13:'Bananas', 14:'Oranges', 15:'Cherries'}
I want to rewrite this dictionary so that the values of dict
become the keys of the new_dict
. Then the values of new_dict
will be the length of each new value, as follows:
new_dict = {'Apples':6, 'Bananas':7, 'Oranges':7, 'Cherries':8}
I am able to swap the values using
new_dict{}
for key,value in dict.items():
new_dict[key] = [value]
print(new_dict[key])
counts = len(new_dict[key])
But the len function here counts how many values are present, not how many characters per value.