Let's say I have a list of people
['foo','bar','baz']
and a list of items
['hat','bag','ball','bat','shoe','stick','pie','phone']
and I want to randomly assign each person an equal amount of items, like so
{
'foo':['hat','bat','stick'],
'bar':['bag','shoe','phone'],
'baz':['ball','pie']
}
I think itertools is the job for this, but I couldn't seem to find the right function as most itertools functions seem to just work on one object.
EDIT: Order does not matter. I just want to randomly assign each person an equal amount of items.
Another solution, using
itertools.cycle:Prints (for example):
If there could be fewer items than persons and each person should have key in output dictionary you can use: