【发布时间】:2017-08-24 17:00:39
【问题描述】:
我有一个如下所示的电影数据集:
1,Toy Story (1995),Adventure|Animation|Children|Comedy|Fantasy
2,Jumanji (1995),Adventure|Children|Fantasy
3,Grumpier Old Men (1995),Comedy|Romance
4,Waiting to Exhale (1995),Comedy|Drama|Romance
5,Father of the Bride Part II (1995),Comedy
6,Heat (1995),Action|Crime|Thriller
7,Sabrina (1995),Comedy|Romance
8,Tom and Huck (1995),Adventure|Children
我只想提取最后一部分(类型部分,例如冒险|动画|儿童|喜剧|奇幻)并将它们存储在列表 list[Adventure, Animation, Children, Comedy, Fantasy] 中。但是,我仍然停留在切片步骤。我不知道该怎么做,因为line[:-1] 没有切片。我使用 Python 2.7
with open(path + 'movie.csv') as f:
for line in f:
print line[:-1]
【问题讨论】: