trying to capture console output and find keyword in that, which approach should be faster? for example: trying to run "ls" command through python and check a keyword is there in the console output
1st Approach having a list of string and then search in each string
list_output = [ "abc", "def", "xyz"]
for i in list_output:
if "ab" in i:
print "found"
break
Please note: Each item in list_output might be a big string itself
2nd Approach having a big string and search a sub string in the big string
string_output = "abcdefxyz"
if "ab" in S:
print "found"
Please note: string_output could be a huge string
Need to stop search as soon as first occurrence is found, no need to search entire string or list further