def merge_sorted(*seqs, **kwargs):
 key = kwargs.get('key', None)
 if (key is None):
  return heapq.merge(*seqs)
 else:
  return _merge_sorted_key(seqs, key)

def merge_sorted ( * seqs , ** kwargs ) : key = kwargs . get ( 'key' , None ) if ( key is None ) : return heapq . merge ( * seqs ) else : return _merge_sorted_key ( seqs , key )
merge and sort a collection of sorted collections this works lazily and only keeps one value from each iterable in memory .