-
-
Save sierrezinal/e871b6da74769446610b0f33d3590483 to your computer and use it in GitHub Desktop.
Revisions
-
Miguel Cabrera created this gist
May 7, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ def delimited(filename, delimiter=' ', bufsize=4096): ''' Creates a generator of word from a file based on a delimiter (by default white space). ''' buf = '' with open(filename) as file: while True: newbuf = file.read(bufsize) if not newbuf: yield buf return buf += newbuf words = buf.split(delimiter) for word in words[:-1]: yield word buf = words[-1]