def combine_repeated_headers(kvset):
 def set_pop(set, item):
  set.remove(item)
  return item
 headers = defaultdict(list)
 keys = set()
 for (key, value) in kvset:
  headers[key].append(value)
  keys.add(key)
 return [(set_pop(keys, k), '\x00'.join(headers[k])) for (k, v) in kvset if (k in keys)]

def combine_repeated_headers ( kvset ) : def set_pop ( set , item ) : set . remove ( item ) return item headers = defaultdict ( list ) keys = set ( ) for ( key , value ) in kvset : headers [ key ] . append ( value ) keys . add ( key ) return [ ( set_pop ( keys , k ) , '\x00' . join ( headers [ k ] ) ) for ( k , v ) in kvset if ( k in keys ) ]
given a list of key-value pairs .