code: def merkle(hashes, func=_merkle_hash256):
      
      # We use append to duplicate the final item in the iterable of hashes, so
      # we need hashes to be a list-like object, regardless of what we were
      # passed.
      hashes = list(iter(hashes))
      # If the passed-in iterable is empty, allow the constructor to choose our
      # return value:
      if not hashes:
          return func()
      # We must make sure the constructor/compressor is called for the case of
      # a single item as well, in which case the loop below is not entered.
      if len(hashes) == 1:
          return func(*hashes)
      # Build up successive layers of the binary hash tree, starting from the
      # bottom. We've reached the root node when the list has been reduced to
      # one element.
      while len(hashes) > 1:
          # For reasons lost to time, Satoshi decided that any traversal though
          # a bitcoin hash tree will have the same number steps. This is because
          # the last element is repeated when there is an odd number of elements
          # in level, resulting in the right portion of the binary tree being
          # extended into a full tower.
          hashes.append(hashes[-1])
          # By creating an iterator and then duplicating it, we cause two items
          # to be pulled out of the hashes array each time through the generator.
          # The last element is ignored if there is an odd number of elements
          # (meaning there was originally an even number, because of the append
          # operation above).
          hashes = list(func(l,r) for l,r in zip(*(iter(hashes),)*2))
      # Return the root node of the Merkle tree to the caller.
      return hashes[0]
docs: Convert an iterable of hashes or hashable objects into a binary tree,
      construct the interior values using a passed-in constructor or compression
      function, and return the root value of the tree. The default compressor is
      the hash256 function, resulting in root-hash for the entire tree.