def reshapelist(shape, seq):
 if (len(shape) == 1):
  return list(seq)
 else:
  n = int((len(seq) / shape[0]))
  return [reshapelist(shape[1:], part) for part in partition(n, seq)]

def reshapelist ( shape , seq ) : if ( len ( shape ) == 1 ) : return list ( seq ) else : n = int ( ( len ( seq ) / shape [ 0 ] ) ) return [ reshapelist ( shape [ 1 : ] , part ) for part in partition ( n , seq ) ]
reshape iterator to nested shape .