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
  • 349
  • 4
  • 12

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
  • 37,862
  • 7
  • 57
  • 71
0

You can use a regular expression.

import re
if re.search(r'a_string|b_string', random_word):
    ...
Barmar
  • 741,623
  • 53
  • 500
  • 612