How do I loop a python list just in 1 line code?
Question:
I have a list and a string:
exclude_list=['2019-1','2019-2']
first_part='Report - 2019-1'
I need a logic to check ,if any item in the list ,is part of the string ,then just print yes,else print no.
something like:
if any(exclude_list) in first_part:
pritn('yes')
else:
print('no')
I can do it this way:
for i in exclude_list:
if i in first_part:
print('yes')
else:
print('no')
But I want it be simpler, any friend can help ?
Answers:
>>> exclude_list=['2019-1','2019-2']
>>> first_part='Report - 2019-1'
>>> any(e in first_part for e in exclude_list)
True
I have a list and a string:
exclude_list=['2019-1','2019-2']
first_part='Report - 2019-1'
I need a logic to check ,if any item in the list ,is part of the string ,then just print yes,else print no.
something like:
if any(exclude_list) in first_part:
pritn('yes')
else:
print('no')
I can do it this way:
for i in exclude_list:
if i in first_part:
print('yes')
else:
print('no')
But I want it be simpler, any friend can help ?
>>> exclude_list=['2019-1','2019-2']
>>> first_part='Report - 2019-1'
>>> any(e in first_part for e in exclude_list)
True