mirror of
https://github.com/wassname/segpy.git
synced 2026-08-11 11:25:46 +08:00
Adds a function for batching iterable series.
This commit is contained in:
@@ -18,6 +18,21 @@ def pairwise(iterable):
|
||||
next(b, None)
|
||||
return izip(a, b)
|
||||
|
||||
def batched(iterable, batch_size):
|
||||
"""
|
||||
"""
|
||||
pending = []
|
||||
batch = pending
|
||||
|
||||
for item in iterable:
|
||||
pending.append(item)
|
||||
if len(pending) == batch_size:
|
||||
batch = pending
|
||||
pending = []
|
||||
yield batch
|
||||
|
||||
if len(pending) > 0:
|
||||
yield batch
|
||||
|
||||
def contains_duplicates(sorted_iterable):
|
||||
"""Determine in an iterable series contains duplicates.
|
||||
|
||||
Reference in New Issue
Block a user