Basically I have converted a tab delimited txt file into a list containing a bunch of lists for each book (title, author, publisher, etc) and I have figured out how to search for something using indexes, but how can I make it so it searches and returns anything that matches even partially.
import csv
import itertools
list_of_books = list(csv.reader(open('bestsellers.txt','rb'), delimiter='\t'))
search = 'Tom Clancy'
for sublist in list_of_books:
if sublist[1] == search:
print sublist
EG. So instead of having to search ‘Tom Clancy’ someone could enter ‘clancy’ and still get all the Tom Clancy novels.
Thanks.
I think this achieves what you’re looking for:
UPDATE:
I think you’ll want to convert both strings to lower case too, like this: