def copy_header_subset(from_r, to_r, condition):
 for (k, v) in from_r.headers.items():
  if condition(k):
   to_r.headers[k] = v

def copy_header_subset ( from_r , to_r , condition ) : for ( k , v ) in from_r . headers . items ( ) : if condition ( k ) : to_r . headers [ k ] = v
will copy desired subset of headers from from_r to to_r .