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
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
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
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"):
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
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