I have a dictionary with the below values :-
test_dict = {'a': ['a1', 'a2'], 'b': ['1.1.1.1:1111', '2.2.2.2:2222', '3.3.3.3:3333,4.4.4.4:4444', '5.5.5.5:5555']}
I need to replace the comma (,
) between 3.3.3.3:3333
and 4.4.4.4:4444
with (',
) which is (single quote comma space) like that of the others.
I tried the code below but the output is coming with double quotes ("
)
val = ','
valnew = '\', \'' # using escape characters - all are single quotes
for k, v in test_dict.items():
for i, s in enumerate(v):
if val in s:
v[i] = s.replace(val, valnew)
print(test_dict)
Output:
{'a': ['a1', 'a2'], 'b': ['1.1.1.1:1111', '2.2.2.2:2222', "3.3.3.3:3333', '4.4.4.4:4444", '5.5.5.5:5555']}
Expected Output:
{'a': ['a1', 'a2'], 'b': ['1.1.1.1:1111', '2.2.2.2:2222', '3.3.3.3:3333', '4.4.4.4:4444', '5.5.5.5:5555']}
Please suggest.