Using regex, best way to get all punctuations from a line in Python?
Question: i tried something like this but it's a bit long:

    
    
    punct_tab=[]
    for line in f:
        tab=line.split()
        for word in tab:
            if re.search(r",",word)!=0:
                   punct_tab.append(',')
            if re.search(r".",word)!=0:
                   punct_tab.append('.')
    
    
             .... ETC
    

Do you have a better idea ?

Thank you


Answer: You can use
[`string.punctuation`](https://docs.python.org/2/library/string.html#string.punctuation):

    
    
    >>> import string
    >>> 
    >>> line = "Hello, world!"
    >>> 
    >>> punctuation = set(string.punctuation)
    >>> print([c for c in line if c in punctuation])
    [',', '!']
    

