我有一个文本文件,我想放入列表.
文本文件如下所示:
New Distribution Votes Rank Title
0000000125 1196672 9.2 The Shawshank Redemption (1994)
0000000125 829707 9.2 The Godfather (1972)
0000000124 547511 9.0 The Godfather: Part II (1974)
0000000124 1160800 8.9 The Dark Knight (2008)
Run Code Online (Sandbox Code Playgroud)
我试过用这段代码拆分列表:
x = open("ratings.list.txt","r")
movread = x.readlines()
x.close()
s = raw_input('Search: ')
for ns in movread:
if s in ns:
print(ns.split()[0:100])
Run Code Online (Sandbox Code Playgroud)
输出:
Search: #1 Single
['1000000103', '56', '6.3', '"#1', 'Single"', '(2006)']
Run Code Online (Sandbox Code Playgroud)
但它并没有给我我想要的输出
它分裂在标题之间的空格上.
如何在不破坏标题的情况下将其拆分为列表?
预期产量:
Search: #1 Single
Distribution Votes Rank Title
['1000000103', '56', '6.3', …Run Code Online (Sandbox Code Playgroud)