如何从CSV文件中读取的字符串中删除逗号,括号,括号和POS标记?
示例输入字符串:
'[("it", "P"), ("was", "VP"), ("sleeping", "N")]' , ' [("is", "P"), ("it", "VP"), ("correct", "N")] '
示例输出:
它正在睡觉,是不是正确
答案 0 :(得分:0)
您可以使用csv.reader的参数控制csv格式:
import csv
data = csv.reader(<file>, quotechar='\'', skipinitialspace=True)
print([" ".join([e[0] for e in eval(field.strip())]) for row in data for field in row])
输出:
['it was sleeping', 'is it correct']