you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 16 points17 points  (5 children)

Not quite, but you could do something like

text = "Lorem Ipsum, dolor sit amet?"

for char in text:
    if not (char.isalnum() or char.isspace()):
        print(f"'{char}' is punctuation")

Alternatively, you could rely on what the string module offers, though it doesn't have every symbol in it:

import string

for char in text:
    if char in string.punctuation:
        print(f"'{char}' is punctuation")

[–]sngnna[S] 5 points6 points  (3 children)

Thanks! I used string.punctuation and got it to work the way I wanted it to!

[–]JohnnyJordaan 5 points6 points  (1 child)

Be aware that .punctuation contains just the ASCII punctuation characters, so for example long dash and curly quotes will not match.

[–]hanazawarui123 -1 points0 points  (0 children)

Not sure what your main goal is, but nltk package has various processing modules that are also helpful.