I'm trying to randomly select items from a list and add them to another list.
The list of elements I'm choosing from looks like this:
for list in lists:
for n,i in enumerate(list):
import random data=[2,3,4,7,8,12,17,24,27,33,35,36,37,38,40,43,44,50,51,54] random.shuffle(data) lists = [data[i:i+len(data)/4] for i in range(0, len(data), len(data)/4)] print(lists)
Randomly pulling from your initial list will have the same effect as shuffling then pulling in order. Splitting into sublists can then be done. If you need the sublists sorted, just map sort over the list afterwards.
You can change the number of groups by altering the divisor of
Edit: I missed this part of your question:
heads = [1,3,5,7] [q.insert(0,p) for p,q in zip(heads,lists)]