Can';不要把它列为一个列表——python
我寻找答案,但找不到答案 我不能把那个str列入名单 如何将其打印为列表 请给我一些建议Can';不要把它列为一个列表——python,python,string,python-3.x,list,Python,String,Python 3.x,List,我寻找答案,但找不到答案 我不能把那个str列入名单 如何将其打印为列表 请给我一些建议 punctuation = ['.','(',')','?',':',':',',','.','!','/','"',"'",'@','#','$','%','^','&','*'] tokenize = str(input("Please enter a sentence " )) tokenize = "".join(char for char in tokenize if char not i
punctuation = ['.','(',')','?',':',':',',','.','!','/','"',"'",'@','#','$','%','^','&','*']
tokenize = str(input("Please enter a sentence " ))
tokenize = "".join(char for char in tokenize if char not in punctuation)
print ("Tokenized:",tokenize.lower())
您可以将
re.split
与交替模式一起使用:
import re
punctuation = ['.','(',')','?',':',':',',','.','!','/','"',"'",'@','#','$','%','^','&','*']
tokenize = str(input("Please enter a sentence: " ))
print(re.split('|'.join(map(re.escape, punctuation)), tokenize))
输入和输出示例:
Please enter a sentence: Hello,World!foo:bar
['Hello', 'World', 'foo', 'bar']
有什么问题吗?这似乎不太清楚。您是否正在尝试将
标记化.lower()
列成一个列表<代码>列表(tokenize.lower())请提供(将其编辑到您的问题中);您对所需内容的描述一点也不清楚,但即使是一个简单的示例输入、预期输出和实际输出,也会让事情变得更加简单。