2013-11-28 16 views

回答

2

您可以使用regular expressions

>>> import re 
>>> re.split("[#$!.\s]+", "The# dog.is.yelling$at!Me to") 
['The', 'dog', 'is', 'yelling', 'at', 'Me', 'to'] 

或者通過字符的任何非字母數字序列分割,如指出@ thg435:

>>> re.split("\W+", "The# dog.is.yelling$at!Me to") 
+4

簡單're.split(R'\ W + 「)' – georg