The following code does what I want:
if myString.startswith(", "):
myString = myString.lstrip(", ")
if myString.endswith(", "):
myString = myString.rstrip(", ")
if re.search(", ,", myString):
myString = re.sub(", ,", "", myString)
Basically, I want it to remove any leading commas, trailing commas, and anywhere two commas appear without anything in between them. This does the trick, but I am betting there is a way to simplify this to make it more elegant and use fewer lines of code.
Any suggestions would really be appreciated. Thanks in advance!