0

Python

How do you take a dictionary (consisting only of strings) and make all of the values in said dictionary lowercase?

jbenfleming
  • 85
  • 3
  • 11

1 Answers1

2
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']}
Taohidul Islam
  • 5,246
  • 3
  • 26
  • 39