如果我有一个字符串,并希望返回一个包含空格的单词,它将如何完成?Python line.split包含一个空格
例如,我有:
line = 'This is a group of words that include #this and @that but not ME ME'
response = [ word for word in line.split() if word.startswith("#") or word.startswith('@') or word.startswith('ME ')]
print response ['#this', '@that', 'ME']
那么急!不打印它,因为空白。
由于
你的实际期望输出是什么? – mgilson
程序应该如何知道ME ME是一个包含空白而不是两个单词的单词? (一个单词怎么能包含一个空格?) –
ME ME不是一个单词,而是它是一个前缀(ME),然后是空格,然后是单词(ME)。我希望程序能够全部选中。道歉不清楚。 – user94628