I have the following problem, I want to remove the punctuation marks at the beginning and at the end but leave the ones in between. Example. and this should turn So if anyone can help me, I would appreciate it Answer You could use a regular expression for this. Just import re at the start of the file, then
Tag: punctuation
Why is Python re not splitting multiple instances of punctuation?
I am trying to split inputted text at spaces, and all special characters like punctuation, while keeping the delimiters. My re pattern works exactly the way I want except that it will not split multiple instances of the punctuation. Here is my re pattern wordsWithPunc = re.split(r'([^-w]+)’,words) If I have a word like “hello” with two punctuation marks after it
Removing punctuation from only the beginning and end of each element in a list in python
I’m fairly new to python (and this community), this is a question branching off of a question asked and answered from a long time ago from here With a list like: Creating a new list x with no punctuation (and deleting empty elements) would be: Output: However, how would I be able to remove all punctuation only from the beginning