Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save markddavidoff/a058f4ad57b645f5a47178dc29b1f8c5 to your computer and use it in GitHub Desktop.
Save markddavidoff/a058f4ad57b645f5a47178dc29b1f8c5 to your computer and use it in GitHub Desktop.
SimpleSortedList
# idk if this works but it was an idea that popped into my head, saving for later here.
class SimpleSortedList(list):
def __init__(self, data=None, cmp=None):
if data is not None:
super(SimpleSortedList, self).__init__(data)
else:
super(SimpleSortedList, self).__init__()
self.cmp = cmp
def insert(self, index, p_object):
list.insert(self,index,p_object)
list.sort(self,self.cmp)
def extend(self, iterable):
list.extend(self, iterable)
list.sort(self,self.cmp)
def append(self, p_object):
list.append(self, p_object)
list.sort(self,self.cmp)
def __iadd__(self, other):
list.__iadd__(self, other)
list.sort(self,self.cmp)
def __add__(self, other):
list.__iadd__(self, other)
list.sort(self,self.cmp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment