0
if "a_string" in random_word or "b_string" in random_word:
    ...

Is there a cleaner, less dense way to write this boolean?

PhantomQuest
  • 309
  • 2
  • 10

2 Answers2

0

In case of if, you could use any to check for the occurrence of either of the two strings

if any(i in random_word for i in ["a_string", "b_string"]):
Sheldore
  • 35,129
  • 6
  • 43
  • 58
0

You can use a regular expression.

import re
if re.search(r'a_string|b_string', random_word):
    ...
Barmar
  • 669,327
  • 51
  • 454
  • 560