We are making a function that receives 2 lists and cuts randomly after shuffling. I even followed the location when it became random, but I didn't know how to cut it together during the cutting process, so I asked.
def random_chunk(li,b, min_chunk=1, max_chunk=3):
it = iter(li)
bb = iter(b)
while True: #2 I hope the list is cut to the same size.
nxt = list(islice(it,randint(min_chunk,max_chunk)))
if nxt:
yield nxt
else:
break
#example
a = [1,2,3,4]
b = [5,6,7,8]
slice = list(random_chunk(a,b))
#print
a = [[2,1], [4,3]]
b = [[6,5], [8,7]]
or
a = [[3,2,1],[4]]
b = [[7,6,5],[8]]
Refer to the code below.
I'd like to work on each list.
import random
a = [1,2,3,4]
b = [5,6,7,8]
random.shuffle(a)
random.shuffle(b)
cnt = 3
print [a[n:n + cnt] for n in range(0, len(a), cnt)]
print [b[n:n + cnt] for n in range(0, len(b), cnt)]
cnt = 2
print [a[n:n + cnt] for n in range(0, len(a), cnt)]
print [b[n:n + cnt] for n in range(0, len(b), cnt)]
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
612 GDB gets version error when attempting to debug with the Presense SDK (IDE)
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.