def regex_last_key(regex):
 def k(obj):
  if regex.search(obj):
   return (1, obj)
  return (0, obj)
 return k

def regex_last_key ( regex ) : def k ( obj ) : if regex . search ( obj ) : return ( 1 , obj ) return ( 0 , obj ) return k
sort key function factory that puts items that match a regular expression last .