Created
February 26, 2018 08:20
-
-
Save cwon/c2c92cbf0d1c438bbeb8209cd03c334b to your computer and use it in GitHub Desktop.
BooleanList
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
import collections.abc | |
class CustomData(): | |
def __init__(self, iterable): | |
self.value = [] | |
for value in iterable: | |
self.value.append(value) | |
def __eq__(self, value): | |
ret = [] | |
for v in self.value: | |
if (v == value): | |
ret.append(True) | |
else: | |
ret.append(False) | |
return tuple(ret) | |
class CustomList(collections.abc.Sequence): | |
def __init__(self, iterable): | |
self.value = [] | |
for value in iterable: | |
self.value.append(value) | |
def __getitem__(self, index): | |
if isinstance(index, tuple): | |
ret = [] | |
for i, value in enumerate(index): | |
if (value == True): | |
ret.append(self.value[i]) | |
return ret | |
return self.value[index] | |
def __len__(self): | |
return len(self.value) | |
data = CustomData([2,2,1,2,1,2,1,2,1,2]) | |
cl = CustomList([1,2,3,4,5,6,7,8,9,10]) | |
t = cl[data == 2] | |
print(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment