def fuse_selections(dsk, head1, head2, merge):
 dsk2 = dict()
 for (k, v) in dsk.items():
  try:
   if (istask(v) and (v[0] == head1) and (v[1] in dsk) and istask(dsk[v[1]]) and (dsk[v[1]][0] == head2)):
    dsk2[k] = merge(v, dsk[v[1]])
   else:
    dsk2[k] = v
  except TypeError:
   dsk2[k] = v
 return dsk2

def fuse_selections ( dsk , head1 , head2 , merge ) : dsk2 = dict ( ) for ( k , v ) in dsk . items ( ) : try : if ( istask ( v ) and ( v [ 0 ] == head1 ) and ( v [ 1 ] in dsk ) and istask ( dsk [ v [ 1 ] ] ) and ( dsk [ v [ 1 ] ] [ 0 ] == head2 ) ) : dsk2 [ k ] = merge ( v , dsk [ v [ 1 ] ] ) else : dsk2 [ k ] = v except TypeError : dsk2 [ k ] = v return dsk2
fuse selections with lower operation .