Searching in a big list file for names using in operator in python

Raaydk

I have downloaded a big file containing movie genres from imdb. The file is so big, that my super computer crash if i try to print everything out from the file.

Well, i need to get some genres on some movies out. To complete that, i made a list in python called movie.

This list contains movie names incl year in the same string. An example you can see here.

['The Shawshank Redemption (1994)\n',
 'The Godfather (1972)\n',
 'The Godfather: Part II (1974)\n',
 'The Dark Knight (2008)\n',
 'Pulp Fiction (1994)\n',

Well i have to make some for loops that for every line in the big file, it should check if one of the movienames appear from my movie list, and if it does it should append it too a new list called genrelist.

So the result would be a new list containing movie name incl genre for them ;)

I tried so far with:

filegenre = open("GenreMod.list", "r")
lines = filegenre.readlines()

for line in lines:
    for item in names:
        if item in line:
            genrelist.append(line)

print genrelist

But here it will only find the last name in the list names. So lets say if it search with the example i paste up, i will only find everything containing --> 'Pulp Fiction (1994) but not the rest?

Have i made some error code or`?

dbell

You need to keep the write file open. Your file is only writing the last loop instance.

with open("genrelist.ext", "w"):
    #do stuff

Nevermind, you are creating a list not a file. Poor Python skills here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Searching for strings within file names using PowerShell

From Dev

Searching a list of names in a text file from user input

From Dev

Searching a file for palindromes and printing them in a list with python

From Dev

Get a list of file names from HDFS using python

From Dev

Searching through a list using recursion in Python?

From Dev

python searching for word in list using regular experssion

From Dev

Searching a pattern in file names with number

From Dev

searching elements of list in file

From Dev

Searching from a list in python

From Dev

Python: searching within a list

From Dev

Searching Active Directory and exporting a list of names in mulitpule groups to a txt file for powershell

From Dev

Insert big list into Cassandra using python

From Dev

Python - searching if string is in file

From Dev

Python file searching trouble

From Dev

Searching through a file in Python

From Dev

Python libtorrent, get file list names

From Dev

Powershell 3.0: Searching specific file names and sending the names to a .txt file

From Dev

Searching files network drive and logging file names

From Dev

18.04 Searching for file names is incredibly slow

From Dev

MemoryError in Python by searching a large file using mmap and re.findall

From Dev

SEARCHING RECORDS FROM MYSQL WITH > OR < OPERATOR USING PHP

From Dev

putting file names in a array using os in python

From Dev

Searching JSON file using bash

From Dev

Python, string slicing (getting file names from a list of file locations)

From Dev

how to extract rows in a big table based on a list file containing the specific names in linux

From Dev

Python searching a large list speed

From Dev

Searching of elements within a list in Python

From Dev

Searching for the rest of a word in a list python

From Dev

Save a big list of lists in python 3 to a binary file

Related Related

  1. 1

    Searching for strings within file names using PowerShell

  2. 2

    Searching a list of names in a text file from user input

  3. 3

    Searching a file for palindromes and printing them in a list with python

  4. 4

    Get a list of file names from HDFS using python

  5. 5

    Searching through a list using recursion in Python?

  6. 6

    python searching for word in list using regular experssion

  7. 7

    Searching a pattern in file names with number

  8. 8

    searching elements of list in file

  9. 9

    Searching from a list in python

  10. 10

    Python: searching within a list

  11. 11

    Searching Active Directory and exporting a list of names in mulitpule groups to a txt file for powershell

  12. 12

    Insert big list into Cassandra using python

  13. 13

    Python - searching if string is in file

  14. 14

    Python file searching trouble

  15. 15

    Searching through a file in Python

  16. 16

    Python libtorrent, get file list names

  17. 17

    Powershell 3.0: Searching specific file names and sending the names to a .txt file

  18. 18

    Searching files network drive and logging file names

  19. 19

    18.04 Searching for file names is incredibly slow

  20. 20

    MemoryError in Python by searching a large file using mmap and re.findall

  21. 21

    SEARCHING RECORDS FROM MYSQL WITH > OR < OPERATOR USING PHP

  22. 22

    putting file names in a array using os in python

  23. 23

    Searching JSON file using bash

  24. 24

    Python, string slicing (getting file names from a list of file locations)

  25. 25

    how to extract rows in a big table based on a list file containing the specific names in linux

  26. 26

    Python searching a large list speed

  27. 27

    Searching of elements within a list in Python

  28. 28

    Searching for the rest of a word in a list python

  29. 29

    Save a big list of lists in python 3 to a binary file

HotTag

Archive