def subDict(d, allowedkeys, flip=False):
 res = {}
 for (k, v) in list(d.items()):
  if ((k in allowedkeys) ^ flip):
   res[k] = v
 return res

def subDict ( d , allowedkeys , flip = False ) : res = { } for ( k , v ) in list ( d . items ( ) ) : if ( ( k in allowedkeys ) ^ flip ) : res [ k ] = v return res
returns a new dictionary with a subset of the entries of d that have on of the allowed keys .