For a list of file names file_names, I try to use code below to filter file names not containing foo or bar:
file_names = ['foo_data.xlsx', 'bar_data.xlsx', 'data.xlsx']
subs = ['foo', 'bar']
for file_name in file_names:
for sub in subs:
if sub not in file_name:
print(file_name)
Output:
foo_data.xlsx
bar_data.xlsx
data.xlsx
data.xlsx
But it's not working out, it should return data.xlsx.
Meanwhile, it works for containing case:
file_names = ['foo_data.xlsx', 'bar_data.xlsx', 'data.xlsx']
subs = ['foo', 'bar']
for file_name in file_names:
for sub in subs:
if sub in file_name:
print(file_name)
Out:
foo_data.xlsx
bar_data.xlsx
Does someone could help to explain what's error in my code and how to fix it? Thanks.
Reference: