Is it possible to find out which condition is satisfied in a multidimensional condition, if this statement?

I am working on a python / beautifulsoup web scraper. I am looking for specific keywords, my expression looks like this:

if 'tribe' in entry or 'ai1ec' in entry or 'tfly' in entry:
            print('Plugin Found!')
            rating = easy
            sheet.cell(row=i, column=12).value = rating

I would like to know which of these keywords makes the statement true. My first instinct would be to write a nested loop to test, but I was not sure if there is a way to capture the value that makes the statement true, which will include less code?

+4
source share
2 answers

, next . , next , ( any, )

cases = ['tribe','allec','tfly']
entry = 'iiii allec rrrr'


p = next((x for x in cases if x in entry),None)
if p is not None:
    print('Plugin Found!',p)
+2

[EDIT: ]

for name in ('tribe', 'ailec', 'tfly'):
    if name in entry:
        print ('Name =', name)
        print('Plugin Found!')
        rating = easy
        sheet.cell(row=i, column=12).value = rating
        break
+2

Source: https://habr.com/ru/post/1692717/


All Articles