From the str.find()
method documentation:
Return -1 if sub is not found.
So the first if
condition tests if string1
is found in x
; if it is, a value other than -1
would be returned. The second if
condition tests if two strings are not present in x
(because only then -1
is returned for both str.find()
calls).
It really should use a membership test (the in
operator) instead:
if 'string1' in x and 'string2' not in x and 'string3' not in x:
return file
The break
after the return
is never reached.
0
solved What does “equals to negative 1” mean in Python?