I have a python dictionary and I would like to find and replace part of the characters in the values of the dictionary. I'm using python 2.7. My dictionary is
data1 = {'customer_order': {'id': '20'},
'patient':
{'birthdate': None,
'medical_proc': None,
'medical_ref': 'HG_CTRL12',
'name': 'Patient_96',
'sex': None},
'physician_name': 'John Doe'
}
I would like to change the underscore to backslash underscore only in the values of the dictionary, in this case only for Patient_96 and HG_CTRL12.
I would like to change it to the following:
data1 = {'customer_order': {'id': '20'},
'patient':
{'birthdate': None,
'medical_proc': None,
'medical_ref': 'HG\_CTRL12',
'name': 'Patient\_96',
'sex': None},
'physician_name': 'John Doe'
}
Thank you for your help
'_'to'_'. I do not see the difference?