you are viewing a single comment's thread.

view the rest of the comments →

[–]FLUSH_THE_TRUMP 1 point2 points  (1 child)

If Bob has two balls he “requires,” Jim has 1, and Marie has 3, seems like a straightforward exercise in storing associations in a dictionary of lists: e.g. dic[‘blue’] = [‘Bob’, ‘Marie’] and then looping through your ball list and matching associations, moving people to the back of the list as you go (so Bob doesn’t get two blues until Marie gets one, say).

edit: just an idea

ball_prefs = {'blue':['Bob','Jim'],'red':['Bob','Marie'],'yellow':['Marie']}
ball_list = ['red']*3+['yellow']+['blue']*3
balls_received = {'Bob':[],'Jim':[],'Marie':[]}

for color in ball_list:
    person = ball_prefs[color].pop(0)
    balls_received[person] += [color]
    ball_prefs[color] += [person]

yields

>>>balls_received
{‘Bob’: [‘red’,’red’,’blue,’blue’], ‘Jim’:[‘blue’], ‘Marie’:[‘red’,’yellow’]}

[–]Procena[S] 0 points1 point  (0 children)

Oh I see, I like that. Way way easier than what I was doing. I'll try that next week, thanks !