Python 仅从电影列表中添加日期
我有一个imdb top250电影列表,在年底发行。我只想从整个列表中添加发布年份。这是我迄今为止的尝试:Python 仅从电影列表中添加日期,python,append,Python,Append,我有一个imdb top250电影列表,在年底发行。我只想从整个列表中添加发布年份。这是我迄今为止的尝试: from pprint import pprint import operator import matplotlib.pyplot as plt top250 = [] newPath = [] ratings = [] top250 = open("top250ratings.list", "r") lines = top250.readlines() newPath = (lin
from pprint import pprint
import operator
import matplotlib.pyplot as plt
top250 = []
newPath = []
ratings = []
top250 = open("top250ratings.list", "r")
lines = top250.readlines()
newPath = (lines[14:])
for row in newPath:
names.append(row[32:])
pprint (names)
部分输出:
[' The Shawshank Redemption (1994)\n',
'The Godfather (1972)\n',
'The Godfather: Part II (1974)\n',
' The Dark Knight (2008)\n',
如果要删除参数,请执行以下操作:
print i[:-1].split()[-1][1:-1]
1994
1972
1974
2008
你可以调整它来获得你需要的内容。那么你到底是怎么做到的呢?你对如何提取这些年有什么想法吗?你可以研究一下,例如,我们尝试过分割,但是没有用,因为列表没有属性分割。你需要分割字符串,例如行,而不是列表,例如名称。所以我必须用另一种方式打开我的文件?我根本没有这么说。您需要使用split处理列表中的每个项目,而不是列表本身。
print i[:-1].split()[-1][1:-1]
1994
1972
1974
2008