Last active
August 14, 2020 04:30
-
-
Save JacobCallahan/b34fc193dbcc1eb769961c11224c5888 to your computer and use it in GitHub Desktop.
A list that you can divide... why not?
This file contains hidden or 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
from collections import UserList | |
class DivList(UserList): | |
def __truediv__(self, num): | |
list_len = len(self.data) | |
start = 0 | |
step, rem = divmod(list_len, num) | |
stop = start + step + bool(rem) | |
outlist = [] | |
while start < list_len: | |
if rem: | |
rem -= 1 | |
outlist.append(self.data[start:stop]) | |
start, stop = stop, stop + step + bool(rem) | |
return outlist | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment