It's been a while since I bugged you guys. But I need the council of my wise advisers once more.
I am trying to write a program that reads a .txt file, breaks each line into words, strips the whitespace and punctuation from the words and returns them in lowercase.
My code is far from done, but when I try to run even this. It only returns one word.
What more puzzling the word isn't even the first one nor the last. It is one near the end.
The code looks right when I read it. What did I do wrong?
import string
def read_book():
f = open("alice_in_wonderland.txt", "r")
for l in f.readlines():
l.strip().translate(None, string.punctuation)
for w in l.split(" "):
if w != "":
return w
def main():
"""
main function
"""
print read_book()
return 0
if __name__ == "__main__":
main()
here is the book if you guys want to run my code:
http://www.gutenberg.org/cache/epub/11/pg11.txt