我不需要列表编号(即) 0,1等。我需要打印没有编号的元素
import pandas as pd
from nltk.tokenize import word_tokenize
import csv
# define punctuation
my_str=pd.read_csv("ef.csv")
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~...'''
word_tokens = word_tokenize(str(my_str))
#mystr=str(my_str)
# remove punctuation from the string
no_punct = [char for char in word_tokens if not char in punctuations]
no_punct=[]
for char in word_tokens:
if char not in punctuations:
#no_punct = no_punct + char
no_punct.append(char)如何使用python中的word tokenize函数删除列表中的编号?我正在获得输出,但我需要不带数字的输出
发布于 2020-05-02 10:53:07
嗯,这可以使用简单的python来完成...
sentence=['Raghavan', 'teaching', 'is', 'excellent', '0', 'Sankar', 'is', 'good', 'at', 'teaching', '1', 'Darwin', 'is', 'extraordinary', 'in', 'teaching']
for i in sentence:
try:
if str(int(float(i))).isnumeric():
sentence.remove(i)
except:
pass
print(sentence)
# output - ['Raghavan', 'teaching', 'is', 'excellent', 'Sankar', 'is', 'good', 'at', 'teaching', 'Darwin', 'is', 'extraordinary', 'in', 'teaching']https://stackoverflow.com/questions/61539180
复制相似问题