def validPolygons(self): ''' returns only 'valid' polygons within our list of geometric shapes ''' previously_rejected= [] for properties in self.shape: # create instance of shape shape= Shape(**properties.__dict__) # if we found a valid convex polygon yield it to our caller but no need to test twice if shape.id not in self.previously_rejected and shape.isConvexPolygon(): yield shape else: # if this is a new reject display warning if shape.id not in self.previously_rejected: print >> stderr, shape.id, "is not a polygon" # keep trace of which shapes we've previoulsy rejected self.previously_rejected.append(shape.id)