Python is not the best language, so I am not so good at the most effective solutions to some of my problems. I have a very large line (from a 30 MB file), and I need to check if this file contains a smaller substring (this line is only a few tens of characters). The way I do it now is:
if small_string in large_string:
But this seems very inefficient because it checks every possible sequence of characters in the file. I know that there will only be an exact match on a new line, so it would be better to read the file as a list and repeat this list so that it matches?
EDIT: To clear up some confusion regarding the "match for newline only", here is an example:
small_string = "This is a line" big_string = "This is a line\nThis is another line\nThis is yet another"
If I'm not mistaken, the in keyword will check all sequences, not just every line.
source share