Python
How do you take a dictionary (consisting only of strings) and make all of the values in said dictionary lowercase?
Python
How do you take a dictionary (consisting only of strings) and make all of the values in said dictionary lowercase?
my_dict ={"first":"ABC","second":"abC","third":"aBc"}
for i in my_dict.keys():
my_dict[i] = my_dict[i].lower()
Update (for list
as dictionary value):
my_dict ={"first":"ABC","second":"abC","third":"aBc","fourth":["Avd","Dfe"]}
for i in my_dict.keys():
if type(my_dict[i]) is list:
my_dict[i]= [j.lower() for j in my_dict[i]]
else:
my_dict[i] = my_dict[i].lower()
print(my_dict)
Output:
{'first': 'abc', 'second': 'abc', 'third': 'abc', 'fourth': ['avd', 'dfe']}