Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #removes punctuation from provided string
- #but preserves punctuation between digits (I am allowing ALL punctuation)
- def remove_punctuation(string):
- results = ""
- previous = ""
- next = ""
- for i, c in enumerate(string):
- if (i > 0):
- previous = string[i - 1]
- if (i + 1 != len(string)):
- next = string[i + 1]
- if (not previous.isdigit() or not next.isdigit()): # if the previous and the next one are not digits
- if (c not in punctuation_list):
- results += c
- else:
- results += c
- return results
- #open_document()
- punctuation_list = ['\\','/',':',',','...','(',')','.','?','!','\"',';','\'','–','’']
- string = "major role — international and — international long-lived—many users’ consumer’s 2004/8ec"
- print(remove_punctuation(string))
Advertisement
Add Comment
Please, Sign In to add comment