Re: list previous or following list elements

2008-06-28 Thread Zentrader
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 -- http://mail.python.org/mailman/listinfo/python-list

Re: list previous or following list elements

2008-06-27 Thread Bruno Desthuilliers
Terry Reedy a écrit : (snip) I believe wordlist = open('words.txt','r').read().split('\n') should give you the list in Python. Or simply: wordlist = open('words.txt').readlines() In any case, wordlist = ['Apple','balcony', 'cartridge', 'damned', 'paper', 'bold', 'typewriter'] for i, word i

Re: list previous or following list elements

2008-06-27 Thread Bruno Desthuilliers
antar2 a écrit : Hello Suppose I have a textfile (text1.txt) with following four words: Apple balcony cartridge damned paper bold typewriter and I want to have a python script that prints the words following the word starting with the letter b (which would be cartridge) or differently put, a

Re: list previous or following list elements

2008-06-26 Thread bearophileHUGS
Terry Reedy: > I believe > wordlist = open('words.txt','r').read().split('\n') > should give you the list in Python. This looks better (but it keeps the newlines too. Untested. Python 2.x): words = open("words.txt").readlines() for i, word in enumerate(words): if word.startswith("b"):

Re: list previous or following list elements

2008-06-26 Thread norseman
Terry Reedy wrote: antar2 wrote: Hello Suppose I have a textfile (text1.txt) with following four words: I see seven. Just say 'list of words' Apple balcony cartridge damned paper bold typewriter and I want to have a python script that prints the words following the word starting with

Re: list previous or following list elements

2008-06-26 Thread Terry Reedy
antar2 wrote: Hello Suppose I have a textfile (text1.txt) with following four words: I see seven. Just say 'list of words' Apple balcony cartridge damned paper bold typewriter and I want to have a python script that prints the words following the word starting with the letter b (which w