def sub_k_list(a, k):
    p = len(a) // k
return a if not p else [sub_k_list(a[:p], k), sub_k_list(a[p:], k)]
k = 2
a = [1, 2, 3, 4, 5, 6, 7, 8]
print(sub_k_list(a, k))
How to split sub-lists into sub-lists k times? (Python)