Pythonic way to check if string x substring of y :
if x in y:
Search if x equivalent to a , b , c , d , e , f or g also Pythonic:
if x in [a,b,c,d,e,f,g]:
But, if any row x contains either a , b , c , d , e , f , or g seems awkward:
if a in x or b in x or c in x or d in x or e in x or f in x or g in x
Is there a more Pythonic method for checking if row x contains a list item?
I know that it is trivial to write this myself, using a loop or using a regular expression:
re.search('(dog|cat|bird|mouse|elephant|pig|cow)', x)
but I was wondering if there is a cleaner way that is not related to regex.
tom Oct 31 '13 at 18:29 2013-10-31 18:29
source share