osdir.com


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

Compare zip lists where order is important


Hi

Trying to find whats changed in this example. Based around work and team reschuffles.

So first I created my current teams and then my shuffled teams.

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]

Then combine.

teams = list(zip(people,team_number))
shuffle_teams = list(zip(shuffle_people, shuffle_team_number))

Then I am attempting to compare for change.

[i for i, j in zip(teams, shuffle_teams) if i != j]

#Result
[('Tim', 1), ('Ally', 2), ('Fred', 3), ('Fredricka', 3)]

#Expecting to see

[('Fredricka', 1),('Tim', 2)]

What's a working way to go about this?

Sayth