python check if word is in certain elements of a list
问题 I was wondering if there was a better way to put: if word==wordList[0] or word==wordList[2] or word==wordList[3] or word==worldList[4] 回答1: Very simple task, and so many ways to deal with it. Exciting! Here is what I think: If you know for sure that wordList is small (else it might be too inefficient), then I recommend using this one: b = word in (wordList[:1] + wordList[2:]) Otherwise I would probably go for this (still, it depends!): b = word in (w for i, w in enumerate(wordList) if i != 1)