A very simple task and so many ways to handle it. Exciting! That's what I think:
If you know for sure that the wordList is small (otherwise it may be too inefficient), I recommend using it:
b = word in (wordList[:1] + wordList[2:])
Otherwise, I will probably go after this (it all the same depends!):
b = word in (w for i, w in enumerate(wordList) if i != 1)
For example, if you want to ignore multiple indexes:
ignore = frozenset([5, 17]) b = word in (w for i, w in enumerate(wordList) if i not in ignore)
It is pythonic and scalable.
However, there are noteworthy alternatives:
Playing around with iterators. Scales, but rather hard to understand. from itertools import chain, islice b = word in chain(islice(wordList, None, 1), islice(wordList, 2, None))
source share