How can I transform the string like this, I need to convert two double quotes to a \".
"Alexandra ""Alex""",Menendez,[email protected],Miami,1
["Alexandra \"Alex\"", "Menendez", "[email protected]", "Miami", "1"]
the return should be a list and that's where I am landing into a problem. This is what I came up with
def parseCsv(sentence):
result = []
new_result = []
sent_1 = list(sentence)
new_str = ""
new_w = ""
for s in sent_1:
if s != ',':
new_str += " ".join(s)
elif new_str:
result.append(new_str)
new_str = ""
result.append(new_str)
for i, w in enumerate(result):
if w.startswith("\"") or w.endswith("\""):
new_w += result[i]
if new_w.startswith("\"") and new_w.endswith("\""):
x = new_w.replace('""', r'\"')
new_result.append(x)
new_w = ""
else:
new_result.append(w)
return new_result
What I get back instead is
['"Alexandra \\"Alex\\""', 'Menendez', '[email protected]', 'Miami', '1']
forloop to print out the contents?string.split(',')to form a list of words separated by commas