def filtany ( entities , * * kw ) : ret = set ( ) for k , v in kw . items ( ) : for entity in entities : if getattr ( entity , k ) ( ) == v : ret . add ( entity ) return ret
python function returning a list of all entities is called
Filter a set of entities based on method return . Use keyword arguments . Example : filtmeth ( entities id = 123 ) filtmeth ( entities name = bart )
def filtany(entities, **kw):
  """Filter a set of entities based on method return. Use keyword arguments.
  
  Example:
    filtmeth(entities, id='123')
    filtmeth(entities, name='bart')

  Multiple filters are 'OR'.
  """
  ret = set()
  for k,v in kw.items():
    for entity in entities:
      if getattr(entity, k)() == v:
        ret.add(entity)
  return ret