Skip to content

Instantly share code, notes, and snippets.

@robomojo
Created October 12, 2013 00:33
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 robomojo/6944140 to your computer and use it in GitHub Desktop.
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
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
# 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