Last active
December 20, 2015 19:28
-
-
Save cizixs/6182945 to your computer and use it in GitHub Desktop.
create a iterator to process every word in a file.
from Python Cookbook!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def words_of_file(thefilepath, line_to_words=str.split) | |
the_file = open(thefilepath) | |
for line in the_file: | |
for word in line_to_words(line): | |
yield word | |
the_file.close() | |
for world in worlds_of_file(thefilepath): | |
dosomethingwith(word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment