Is it possible to find out which condition is being met in a multi condition if then statement?
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Melt
--
Chapters
00:00 Question
00:42 Accepted answer (Score 2)
01:11 Answer 2 (Score 2)
01:28 Thank you
--
Full question
https://stackoverflow.com/questions/4844...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #beautifulsoup
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Melt
--
Chapters
00:00 Question
00:42 Accepted answer (Score 2)
01:11 Answer 2 (Score 2)
01:28 Thank you
--
Full question
https://stackoverflow.com/questions/4844...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #beautifulsoup
#avk47
ANSWER 1
Score 2
[EDIT: changed to only find first name]
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
ACCEPTED ANSWER
Score 2
I would use a generator comprehension that I would pass to next with a default value. If the comprehension doesn't find anything, next returns the default value, else it returns the first found and stops there (kind of any, but which stores the result)
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)