Feb-15-2020, 12:34 AM
Hi guys,
my script must read a text file and produce an output. it works quite well but a piece of his code is very slow (it because of some instructions at the beginning of my scrtipt). they are like the example below and take around 30 seconds to read a text file composed by around 300000 lines:
my script must read a text file and produce an output. it works quite well but a piece of his code is very slow (it because of some instructions at the beginning of my scrtipt). they are like the example below and take around 30 seconds to read a text file composed by around 300000 lines:
x = "" y = "" .. .. for line in text: list = line.split() if "xxxx" in line and "t" in list[5] and "z" not in list[5] x = x + line elif "xxxx" in line and "a" not in list[7] and "b" not in list[8] and " hola " not in line: y = y + line elif..when I have many "not in" or "in" instructions for the same string, I tried to use this custom function, but unfortunately it doesn't solve the time issue:
def find_all_strings(text, strings_to_find, in_or_not_in): if in_or_not_in == "in": if all (string in text for string in strings_to_find): return True else: return False elif in_or_not_in == "not_in": if all (string not in text for string in strings_to_find): return True else: return Falseis there a way to improve the code? my goal is implement a kind of "grep" and "grep -v" commands in the text document to take from it different configuration lines.