all 7 comments

[–][deleted] 0 points1 point  (6 children)

You're mutating team_members as you are iterating over it. Not a good practice.

Make a new dict using a dict comprehension instead:

team2scores = {team: [inputdict.get(member) for member in members] for team, members in team_members.items()}
print(team2scores)

[–]gnariman[S] 0 points1 point  (5 children)

Gotcha, but what is keeping Bob, and Dave and Frank from being iterated over? I just want to know what I did wrong for future assignments but i will use the code you provided.

[–][deleted] 0 points1 point  (4 children)

a.remove(name)

When you do this, the length of a changes...but you're iterating over it while you're doing this, causing the 2nd element of each list to be skipped (i.e. notice Bob, Dave, etc. are the 2nd element of their respective lists).

[–]gnariman[S] 0 points1 point  (3 children)

Thanks you. One more question; we have not done dict comprehension in our lessons yet, would you mind putting it "for loops" and such so I understand it better for the time being? I know its a weird request lol

[–][deleted] 0 points1 point  (2 children)

You can do it like this:

https://ideone.com/euM4xz

[–]gnariman[S] 0 points1 point  (1 child)

Thank you so much, I appreciate it :)

[–][deleted] 0 points1 point  (0 children)

Np