osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: Compare zip lists where order is important


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