Skip to content

Instantly share code, notes, and snippets.

@israelst
Last active February 3, 2019 17:02
Show Gist options
  • Save israelst/8bd3fac0c48e70c5aed009ad7b7eb5b5 to your computer and use it in GitHub Desktop.
Save israelst/8bd3fac0c48e70c5aed009ad7b7eb5b5 to your computer and use it in GitHub Desktop.
Helper functions to data structures hacking
def chunk_indexes(size, chunk_size):
start = (size % chunk_size) or chunk_size
upper_boundary = list(range(start, size + 1, chunk_size))
lower_boundary = [0] + upper_boundary[:-1]
return zip(lower_boundary, upper_boundary)
def iterlinked(node):
if not node: raise StopIteration
yield node.value
while node.next:
node = node.next
yield node.value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment