I am trying to remove all the \r\n from the python dictionary. What is the easiest way to do so. My dictionary is looking like this at the moment -
{'': '34.8\r\n',
'Mozzarella di Giovanni\r\n': '34.8\r\n',
'Queso Cabrales\r\n': '14\r\n',
'Singaporean Hokkien Fried Mee\r\n': '9.8\r\n'
}
EDIT : Here's what I'm trying -
for key, values in productDictionary.items() :
key.strip()
values.strip()
key.strip('"\"r')
key.strip('\\n')
values.strip('\\r\\n')
print productDictionary
And the output is still the same.
Using a dictionary comprehension:
clean_dict = {key.strip(): item.strip() for key, item in my_dict.items()}
The strip() function removes newlines, spaces, and tabs from the front and back of a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With