convert dictionary keys/values to lowercase in python
my_dict = {'KEY1': "Hello", 'Key2': "World"}
new_dict = dict((k.lower(), v) for k, v in my_dict .items())
print(new_dict
3.8
5
my_dict = {'KEY1': "Hello", 'Key2': "World"}
new_dict = dict((k.upper(), v.upper()) for k, v in my_dict .items())
print(new_dict)
Thank you!
5
0
4
1
def lower_dict(d):
new_dict = dict((k.lower(), v) for k, v in d.items())
return new_dict
a = {'Foo': "Hello", 'Bar': "World"}
print(lower_dict(a))
Thank you!
1
0
4.2
5
def lower_dict(d):
new_dict = dict((k.lower(), v.lower()) for k, v in d.items())
return new_dict
a = {'Foo': "Hello", 'Bar': "World"}
print(lower_dict(a))
Thank you!
5
0
3.75
8
my_dict = {'KEY1': "Hello", 'Key2': "World"}
new_dict = dict((k, v.lower()) for k, v in my_dict .items())
print(new_dict)
Thank you!
8
0
Are there any code examples left?
New code examples in category Python