Last active
February 3, 2019 17:02
-
-
Save israelst/8bd3fac0c48e70c5aed009ad7b7eb5b5 to your computer and use it in GitHub Desktop.
Helper functions to data structures hacking
This file contains 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 characters
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) |
This file contains 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 characters
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