-2
a = '/dvi/abcbbb'

if ('/dev/' in a) or ('/dv/' in a) or ('/dvi/' in a):
     print(a)
/dvi/abcbbb

Can we do it without the OR statements in Python ?

  • 1
    `if any(x in a for x in ('/dev', '/dv/', '/dvi/')):` – Mandera Jun 22 '21 at 10:52
  • 1
    Check out this thread -- [https://stackoverflow.com/questions/3389574/check-if-multiple-strings-exist-in-another-string/](https://stackoverflow.com/questions/3389574/check-if-multiple-strings-exist-in-another-string/) – Kabilan Mohanraj Jun 22 '21 at 10:53

1 Answers1

0

You can reverse the check:

if os.path.dirname(a) in ["/dev", "/dv", "/dvi"]:
    print(a)
Rajat Jain
  • 452
  • 1
  • 6
  • 16