Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
fix take_n with more efficient implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
brilee committed Jan 24, 2017
1 parent 6236b20 commit aaa22dc
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions load_data_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
CHUNK_HEADER_FORMAT = "iii?"
CHUNK_HEADER_SIZE = struct.calcsize(CHUNK_HEADER_FORMAT)

def take_n(n, iterator):
result = []
try:
for i in range(n):
result.append(next(iterator))
except StopIteration:
pass
finally:
return result
def take_n(n, iterable):
return list(itertools.islice(iterable, n))

def iter_chunks(chunk_size, iterator):
while True:
Expand Down

0 comments on commit aaa22dc

Please sign in to comment.