On Thursday, 29 August 2019 20:33:46 UTC+10, Peter Otten wrote: > Sayth Renshaw wrote: > > > will find the added > > pairs, but ignore the removed ones. Is that what you want? > > > > Yes, I think. I want to find the changed pairs. The people that moved team > > numbers. > > To find the people that moved team numbers I would tear the pairs apart. > Like: > > >>> people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] > >>> team_number = [1,1,2,2,3,3] > >>> shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] > >>> shuffle_team_number = [1,1,2,2,3,3] > >>> old = dict(zip(people, team_number)) > >>> new = dict(zip(shuffle_people, shuffle_team_number)) > >>> for name in old.keys() & new.keys(): > ... old_team = old[name] > ... new_team = new[name] > ... if old_team != new_team: > ... print(name, "went from", old_team, "to", new_team) > ... > Tim went from 1 to 2 > Fredricka went from 3 to 1 > Ally went from 2 to 3
The reason I opted away from Dictionaries is if there was a team with people with same name. Then the keys would be the same. So if Sally left and team 2 had one Tim move in and a new Tim start. shuffle_people = ["Fredricka","Bill","Tim","Tim","Ally","Fred"] shuffle_team_number = [1,1,2,2,3,3] becomes {'Fredricka': 1, 'Bill': 1, 'Tim': 2, 'Ally': 3, 'Fred': 3} This still appears to work but is wrong. for name in old.keys()& new.keys(): old_team = old[name] new_team = new[name] if old_team != new_team: print(name, "went from", old_team, "to", new_team) Ally went from 2 to 3 Tim went from 1 to 2 Fredricka went from 3 to 1 But I guess in reality I would use a UID and then look up the UID in a list or database. Cheers Sayth -- https://mail.python.org/mailman/listinfo/python-list