Last active
March 23, 2016 21:36
-
-
Save nitori/68c979c8e88607502db5 to your computer and use it in GitHub Desktop.
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
class szip: | |
def __init__(self, *sequences): | |
self.sequences = sequences | |
def __len__(self): | |
return min(len(seq) for seq in self.sequences) | |
def __getitem__(self, index): | |
if isinstance(index, slice): | |
return szip(*(seq[index] for seq in self.sequences)) | |
else: | |
return tuple(seq[index] for seq in self.sequences) | |
def __contains__(self, item): | |
return item in zip(*self.sequences) | |
def __iter__(self): | |
return zip(*self.sequences) | |
def __repr__(self): | |
return '<szip object at 0x{:x}>'.format(id(self)) |
Author
nitori
commented
Mar 23, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment