def make_binary_tree(fn, args, **kwargs):
 count = len(args)
 if (not count):
  raise ValueError('Called make_binary_tree with empty list')
 elif (count == 1):
  return args[0]
 half = (count // 2)
 return fn(make_binary_tree(fn, args[:half], **kwargs), make_binary_tree(fn, args[half:], **kwargs), **kwargs)

def make_binary_tree ( fn , args , ** kwargs ) : count = len ( args ) if ( not count ) : raise ValueError ( 'Called make_binary_tree with empty list' ) elif ( count == 1 ) : return args [ 0 ] half = ( count // 2 ) return fn ( make_binary_tree ( fn , args [ : half ] , ** kwargs ) , make_binary_tree ( fn , args [ half : ] , ** kwargs ) , ** kwargs )
takes a function/class that takes two positional arguments and a list of arguments and returns a binary tree of results/instances .