Comment faire plusieurs listes comme ceci:Modifier la liste en python
['The Lord of the Rings: The Fellowship of the Ring (2001)']
['The Lord of the Rings: The Two Towers (2002)']
['"5 Second Movies" (2007) {The Lord of the Rings and the Two Towers (#1.63)}']
Dans une telle liste:
['The Lord of the Rings: The Fellowship of the Ring (2001)',
'The Lord of the Rings: The Two Towers (2002)',
'"5 Second Movies" (2007) {The Lord of the Rings and the Two Towers (#1.63)}']
J'ai essayé:
x = open("ratings.list.txt","r")
movread = x.readlines()
x.close()
#s = raw_input('Search: ').lower()
for ns in movread:
if 'the lord of the' in ns.lower():
d = re.split('\s+',ns,4)
Title = d[4].rstrip()
Rating= d[3]
lists = [Title]
combined = [item for sublist in lists for item in sublist]
print combined
Mais son donne moi cette sortie:
['T', 'h', 'e', ' ', 'L', 'o', 'r', 'd', ' ', 'o', 'f', ' ', 't', 'h', 'e', ' ', 'R', 'i', 'n', 'g', 's', ':', ' ', 'T', 'h', 'e', ' ', 'R', 'e', 't', 'u', 'r', 'n', ' ', 'o', 'f', ' ', 't', 'h', 'e', ' ', 'K', 'i', 'n', 'g', ' ', '(', '2', '0', '0', '3', ')']
['T', 'h', 'e', ' ', 'L', 'o', 'r', 'd', ' ', 'o', 'f', ' ', 't', 'h', 'e', ' ', 'R', 'i', 'n', 'g', 's', ':', ' ', 'T', 'h', 'e', ' ', 'F', 'e', 'l', 'l', 'o', 'w', 's', 'h', 'i', 'p', ' ', 'o', 'f', ' ', 't', 'h', 'e', ' ', 'R', 'i', 'n', 'g', ' ', '(', '2', '0', '0', '1', ')']
Merci pour l'aide les gars: D
MISE À JOUR
Le look de fichier comme celui-ci (son d'une liste de tous les films sur IMDB, de sorte que la taille est énorme):
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)
0000000124 920221 8.9 Pulp Fiction (1994)
0000000124 358790 8.9 Il buono, il brutto, il cattivo. (1966)
000000.9 Schindler's List (1993)
0000000133 297241 8.9 12 Angry Men (1957)
0000000124 854409 8.9 The Lord of the Rings: The Return of the King (2003)
000000.8 Fight Club (1999)
0000000124 880827 8.8 The Lord of the Rings: The Fellowship of the Ring (2001)
000000.8 Star Wars: Episode V - The Empire Strikes Back (1980)
0000000124 953140 8.7 Inception (2010)
Que diriez-vous juste de '[sub [0] pour sub dans l'original]'? –
Je vous suggère de lire le fichier et de le diviser par newlines plutôt que par caractère. –
Comment je fais ça? Je ne suis pas bon en python juste commencé avec ça! @ Stupid.Fat.Cat –