list1 = [1,2,3,4,5]
list2 = [2,3,4,1,2]
list3 = [2,4,6,2,1]
def random_chunk(li, min_chunk=1, max_chunk= 3):
it = iter(li)
while True:
nxt = list(islice(it,randint(min_chunk,max_chunk)))
if nxt:
yield nxt
else:
break
def shuffle(a, b, c):
assert len(a) == len(b) == len(c)
start_state = random.getstate()
random.shuffle(a)
random.setstate(start_state)
random.shuffle(b)
random.setstate(start_state)
random.shuffle(c)
random.setstate(start_state)
shuffle(list1, list2, list3)
slice = list(random_chunk(list1))
After mixing the lists randomly, I ended up coding randomly using the chunk function. But it is not easy to want the two lists to be equally divided. How can I cut multiple lists the same way? For example, when list1 = [1,2,3,4,5] is cut into [1,2], [3,4,5], list2 is also [2,3], [4,2,1 ].I really appreciate it if you let me know.