def itemfilter(predicate, d, factory=dict):
 rv = factory()
 for item in iteritems(d):
  if predicate(item):
   (k, v) = item
   rv[k] = v
 return rv

def itemfilter ( predicate , d , factory = dict ) : rv = factory ( ) for item in iteritems ( d ) : if predicate ( item ) : ( k , v ) = item rv [ k ] = v return rv
filter items in dictionary by item .