我想通过删除除字母字符之外的所有内容来拆分字符串。
默认情况下,split仅按单词之间的空格进行分割。但我想按字母字符以外的所有内容进行分割。如何添加多个分隔符split?
例如:
word1 = input().lower().split()
# if you input " has 15 science@and^engineering--departments, affiliated centers, Bandar Abbas&&and Mahshahr."
#the result will be ['has', '15', 'science@and^engineering--departments,', 'affiliated', 'centers,', 'bandar', 'abbas&&and', 'mahshahr.']
Run Code Online (Sandbox Code Playgroud)
但我正在寻找这样的结果:
['has', '15', 'science', 'and', 'engineering', 'departments', 'affiliated', 'centers', 'bandar', 'abbas', 'and', 'mahshahr']
Run Code Online (Sandbox Code Playgroud)