I wrote an if statement like:
if word in vocab: print word However, I also would like to know the matched word index in vocab.
Is there any way in Python can do this?
I just come up a solution that use vocab.index(word) to get the index, but this way go through the array twice (one in if statement, one call index()). I wonder there should be more efficiency method.
Thanks.
inreturns only True or False. Also read about: EAFP.indexand.findmethods, and BTW you can easily get the value once you've the index.