This handy function turns file into stream of words stripped of punctuation, whitespace and digits, but does not split for example we'd to two words. If you want that you can further process yielded words or change the definition.
lowercase word generator
peter_budo
commented:
Nice sample +15
import string
def get_lower_words(filein):
for line in filein:
while line:
word, match, line = line.partition(' ')
word = word.lower().strip(string.punctuation+
string.whitespace+
string.digits)
if word: yield word
for word in get_lower_words(open('11.txt')):
print word
griswolf 304
Veteran Poster
TrustyTony 888
pyMod Team Colleague Featured Poster
TrustyTony 888
pyMod Team Colleague Featured Poster
TrustyTony 888
pyMod Team Colleague Featured Poster
griswolf 304
Veteran Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.