I have a string like this '[[20, 20.4,aa], [c, 10.5, eee]]'.
My aim is to enclose the characters inside single quotes and leave the numbers as it is.
For example:
examples:
s1 = "[[20, 20.4, aa], [c, 10.5, eee]]"
s2 = "[[a , bg, 20], [cff, 20, edd]]"
required:
s1 = "[[20, 20.4,'aa'], ['c', 10.5, 'eee']]"
s2 = "[[a , 'bg', 20], ['cff', 20, 'edd']]"
I have done so far this:
s = '[[20, 20.4,a], [c, 10.5, e]]'
s = ''.join(["'"+ i + "'" if i.isalpha() else i for i in s])
s # "[[20, 20.4,'a'], ['c', 10.5, 'e']]"
But it works only for single characters. If I have aa it will give 'a''a' which is wrong.
How the problem can be fixed?