Working with Python.
I have some huge textfiles and would like to filter them. books.txt has a discription of books in it, genre.txt the all the titles with their genres.
Now I want to just work with the fantasy-genre. Here my code so far:
open(“genrefile.txt”,‘w’).writelines(line for line in open(“genres.txt”) if “fantasy” in line)
open(“finalfile.txt”, ‘w’).writelines(l for l in open(“books.txt”) if open(“genrefile.txt”) in l )
I get the genrefile with just the fantasy-titles, but how do I apply this filtred file to the books.txt?
I tried to make the genrefilde.txt to a String, but when I use
genrestring = open(“genrefile.txt”)
it just delets all the content.
Thanks in advance!