I want to know, is there a way to check if a string is present in the list of strings ;
I want some thing like :
a = ["one", "two", "three", "four"]
b = "three"
if b in a:
# return index of a
else:
# do something else
I want to know, is there a way to check if a string is present in the list of strings ;
I want some thing like :
a = ["one", "two", "three", "four"]
b = "three"
if b in a:
# return index of a
else:
# do something else
If all you want to do is return the index of b inside of a, if b is present, and so something else if it is not, try this : -
a = ["one", "two", "three", "four"]
b = "three"
try:
print a.index(b) #if inside the function, use return
except:
#do something2
As other experts said, I would highly recommend you try it with your own Python 2.x/3.x environment.
If you for some reason don't have it in hand, try some online IDEs, for example https://ideone.com/