I have a string like this
gas,buck,12345,10fifty
how can I end up with this string?
gas,,12345,10fifty
>Solution :
One option might be using list comprehension with split and join, although it might be inefficient:
s = "gas,buck,12345,10fifty"
output = ",".join("" if i == 1 else x for i, x in enumerate(s.split(",")))
print(output) # gas,,12345,10fifty
Alternatively, in this specific case, you can use re:
output = re.sub(',.*?,', ',,', s, count=1)
print(output) # gas,,12345,10fifty