summer update

This commit is contained in:
bendtherules
2014-07-07 18:18:56 -07:00
parent d1f4cc61cc
commit 0cf8b29572
58 changed files with 9282 additions and 766 deletions
+19 -7
View File
@@ -1,20 +1,32 @@
# move it to utils.py
# also look at frozensets
# look at import collections - lot of good data structures
# learn about co-routines (returning generators from generators i.e. yield
# statement)
class uniquelist(list):
''' A list whose every value is unique.
uniquelist.append(val) or __setitem__(pos,val) i.e. uniquelist[pos]=val is ignored if val is already in uniquelist.
Returns True if the value is added, else returns False. '''
def __setitem__(self,pos,val):
def __setitem__(self, pos, val):
if val not in self:
super(uniquelist,self).__setitem__(pos,val)
super(uniquelist, self).__setitem__(pos, val)
return True
else:
return False
def append(self,val):
def append(self, val):
if val not in self:
super(uniquelist,self).append(val)
super(uniquelist, self).append(val)
return True
else:
return False
def extend(self,iterable):
for temp in iterable: # todo: use yield so that it is not copied into memory
def extend(self, iterable):
# todo: use yield so that it is not copied into memory
for temp in iterable:
self.append(temp)
# Todo: Allow for type checking by allowing a type_of_members to be set
# Todo: Allow for type checking by allowing a type_of_members to be set