Well, if your words are not too big (that is, they will fit into the memory), then here is an easy way to do this (I assume that these are all words).
from bisect import bisect_left f = open('myfile.csv') words = [] for line in f: words.extend(line.strip().split(',')) wordtofind = 'bacon' ind = bisect_left(words,wordtofind) if words[ind] == wordtofind: print '%s was found!' % wordtofind
It may take a minute to load all values ββfrom a file. Binary search is used to search for your words. In this case, I was looking for bacon (who would not be looking for bacon?). If there are duplicate values, you can also use bisect_right to find the index 1 behind the rightmost element, which is equal to the value you are looking for. You can still use this if you have key: value pairs. You just need to make each object in the list of words a list of [key, value].
Side note
I do not think that you really can go from line to line in a csv file very easily. You see, these files are basically just long lines with \ n characters indicating new lines.
source share