textbisect - Binary search in a text file¶
This module provides functionality to search inside sorted text files. The lines of the files need not be all of the same length. The module contains the following functions:
- text_bisect_left(a, x, lo=0, hi=None, key=lambda x: ...)¶
Locates the insertion point for line
xin seekable filelike objectaconsisting of a number of lines;xmust be specified without a trailing newline.amust use\nas the newline character and must not perform any line endings translation (useopen(..., newline='\n')). The parametersloandhi, if specified, must be absolute positions within objecta, and specify which part ofato search; the default is to search the entirea. The character pointed to byhi(or the last character of the object, ifhiis unspecified) must be a newline.keyis a function that is used to compare each line ofawithx; line endings are removed from the lines ofabefore comparison.amust be sorted or the result will be undefined. Ifxcompares equal to a line ina, the returned insertion point is the beginning of that line. The initial position ofais discarded. The function returns the insertion point, which is an integer betweenloandhi+1, pointing to the beginning of a line; when it exits,ais positioned there.
- text_bisect_right(a, x, lo=0, hi=None, key=lambda x: ...)¶
The same as
text_bisect_left(), except that ifxcompares equal to a line ina, the returned insertion point is the beginning of the next line.
- text_bisect(a, x, lo=0, hi=None, key=lambda x: ...)¶
Same as
text_bisect_right().