【发布时间】:2017-09-12 20:30:29
【问题描述】:
这是我正在读取的.txt 文件中的一行,我将其分配给x:
x = "Wild_lions live mostly in “Africa”"
result = re.split('[^a-zA-Z0-9]+', x)
我最终得到:
['Wild', 'lions', 'live', 'mostly', 'in', 'Africa', ''] # (there's an empty space character as the last element)
为什么最后有一个空格?我意识到我可以通过 result.remove(' ') 来摆脱空间,但对于大文件,我认为这将非常低效。
【问题讨论】:
标签: python regex split expression