def tree_hash(fo):
 hashes = []
 hashes.extend(fo)
 while (len(hashes) > 1):
  new_hashes = []
  while True:
   if (len(hashes) > 1):
    first = hashes.pop(0)
    second = hashes.pop(0)
    new_hashes.append(hashlib.sha256((first + second)).digest())
   elif (len(hashes) == 1):
    only = hashes.pop(0)
    new_hashes.append(only)
   else:
    break
  hashes.extend(new_hashes)
 return hashes[0]

def tree_hash ( fo ) : hashes = [ ] hashes . extend ( fo ) while ( len ( hashes ) > 1 ) : new_hashes = [ ] while True : if ( len ( hashes ) > 1 ) : first = hashes . pop ( 0 ) second = hashes . pop ( 0 ) new_hashes . append ( hashlib . sha256 ( ( first + second ) ) . digest ( ) ) elif ( len ( hashes ) == 1 ) : only = hashes . pop ( 0 ) new_hashes . append ( only ) else : break hashes . extend ( new_hashes ) return hashes [ 0 ]
given a hash of each 1mb chunk this will hash together adjacent hashes until it ends up with one big one .