Created
October 12, 2013 00:33
-
-
Save robomojo/6944140 to your computer and use it in GitHub Desktop.
an hopefully extendable framework for getting groups of names from a big list of names
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 finder | |
objects = ( | |
'door', | |
'mirror', | |
'bonnet', | |
'lense', | |
'focallength', | |
'lenscap', | |
'milkcrate', | |
'carpet', | |
'bin', | |
'missy', | |
) | |
car = finder.ObjectList (( | |
( | |
'door', | |
'mirror', | |
'bonnet', | |
), | |
)) | |
camera = finder.ObjectList (( | |
( | |
'lense', | |
'focallength', | |
'lenscap', | |
), | |
)) | |
cats = finder.ObjectList (( | |
( | |
'missy', | |
'fluffy', | |
'spotty', | |
), | |
)) | |
result = finder.ObjectSorter((objects,(car,camera,cats))) | |
print car.list | |
print car.isFull | |
print camera.list | |
print camera.isFull | |
print cats.list | |
print cats.isFull |
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
# return a list of objects | |
class ObjectList: | |
def __init__ (self, args): | |
( | |
self.criteria, | |
) = args | |
self.isFull = False | |
self.list = [] | |
def add(self,object): | |
''' | |
add, and then check isFull() | |
''' | |
if object not in self.list: | |
self.list.append(object) | |
self.checkIsFull() | |
def checkIsFull(self): | |
''' | |
this object has found all objects in its criteria. | |
''' | |
foundall = len(self.list)==len(self.criteria) | |
self.isFull=True if foundall else False | |
class ObjectSorter: | |
def __init__ (self, args): | |
( | |
self.objects, | |
self.criteria | |
) = args | |
self.sort() | |
def sort (self): | |
''' | |
Grow each objectlist | |
''' | |
for objectlist in self.criteria: | |
for each in self.objects: | |
for criteria in objectlist.criteria: | |
if self.matchName(each,criteria): objectlist.add(each) | |
def matchName (self,string1,string2): | |
''' | |
Simple Match | |
''' | |
return True if string1 == string2 else False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment