hoe to set all the keys'value from a dictionnary to '' in python

You can iterate through each key in the dictionary and set its value to an empty string using the for loop.

main.py
my_dict = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}

for key in my_dict:
    my_dict[key] = ''
108 chars
5 lines

Alternatively, you can use a dictionary comprehension to set all the values to an empty string.

main.py
my_dict = {key: '' for key in my_dict}
39 chars
2 lines

gistlibby LogSnag