list previous or following list elements

Zentrader zentraders at gmail.com
Sat Jun 28 21:57:36 CEST 2008


To be completely correct, you should allow for the possibility that
the word found is the last word in the list
for j, word in enumerate(words):
    if (word.startswith("b")) and (j+1 < len(words)):
        print words[j+1]
        break



More information about the Python-list mailing list