我正在尝试读取CSV文件(包含一列)并将其转换为列表。以下是我的代码。
import csv
path = "/tmp/list.csv"
with open(path, 'r') as f:
reader = csv.reader(f)
your_list = list(reader)
print(your_list)
List.csv:
apple
banana
orange
pear
代码输出:
[['apple'], ['banana'], ['orange'], ['pear']]
但是我可以生成以下格式的输出吗?
预期产出:
["apple","banana","orange","pear"]