Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';不要把它列为一个列表——python_Python_String_Python 3.x_List - Fatal编程技术网

Can';不要把它列为一个列表——python

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

我寻找答案,但找不到答案

我不能把那个str列入名单 如何将其打印为列表

请给我一些建议

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())请提供(将其编辑到您的问题中);您对所需内容的描述一点也不清楚,但即使是一个简单的示例输入、预期输出和实际输出,也会让事情变得更加简单。