Skip to content

Instantly share code, notes, and snippets.

@cwon
Created February 26, 2018 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwon/c2c92cbf0d1c438bbeb8209cd03c334b to your computer and use it in GitHub Desktop.
Save cwon/c2c92cbf0d1c438bbeb8209cd03c334b to your computer and use it in GitHub Desktop.
BooleanList
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