Setting items from a list to another list (both containing class instances) in random groups in python -


i have 2 lists containing instances 2 classes. want assign groups of items first list second. have right method add_agent. don't know how iterate , exhaust both lists in right order.

for example: 20 agents assigned 5 families in random groups of 0, 1, 2, 3 or 4.

my code far:

def allocate_to_family(families, agents):     dummy_agent in agents:         dummy_family in families:             num_members = numpy.random.choice(4)             while num_members != 0:                 dummy_family.add_agent(dummy_agent)                 num_members -= 1 

thanks bunch!

you can use random.sample choose random group of families assign agents :

def allocate_to_family(families, agents):      dummy_family in families:          dummy_agent in random.sample(agents, 4):                                            dummy_family.add_agent(dummy_agent) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -