Skip to content

Instantly share code, notes, and snippets.

@hzbd
Forked from sivy/shard_array.py
Created April 23, 2013 17:42
Show Gist options
  • Save hzbd/5445739 to your computer and use it in GitHub Desktop.
Save hzbd/5445739 to your computer and use it in GitHub Desktop.
def _shard_array(inlist, shard_size):
# inlist = 150-element list
# shard_size = 40
num_shards = len(inlist) / shard_size
# num_shards == 3
shards = []
for i in range(num_shards):
# i == 0
start = shard_size * i # start == 0, then 40, then 80...
end = shard_size * (i + 1) - 1 # end == 39, then 79, then 119...
shards.append(inlist[start:end])
return shards
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment