4 ms·
M, N = 10, 100 apples = xrange(N) L = random.sample(apples, N) crates = [L[i:i+M] for i in xrange(0, N, M)]
by d0mine 17y ago
M, N = 10, 100
apples = xrange(N)
L = random.sample(apples, N)
crates = [L[i:i+M] for i in xrange(0, N, M)]
- metamemetics 17y agoYou are not randomly placing apples in crates. You are putting sequential groups of 10 in crates. 10 is the average number of apples that will be in each crate, but it is possible no crate has 10 apples in it.
- deleted 17y ago[deleted]