Created
July 26, 2014 21:28
-
-
Save anonymous/22f3b363d834e2bfa818 to your computer and use it in GitHub Desktop.
StackOverflow question #24975218
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
class Person(object): | |
def __init__(self, name, sup): | |
self.name = name | |
self.sup = sup | |
yesterday = [ | |
Person("Bill", "Sup A"), | |
Person("Harry", "Sup A"), | |
Person("Sally", "Sup A"), | |
Person("John", "Sup D"), | |
Person("Matt", "Sup D"), | |
Person("Steve", "Sup N"), | |
Person("Jen", "Sup N"), | |
Person("Sue", "Sup N"), | |
Person("Rob", "Sup N") | |
] | |
today = [ | |
Person("Bill", "Sup B"), | |
Person("Harry", "Sup B"), | |
Person("Sally", "Sup B"), | |
Person("John", "Sup C"), | |
Person("Matt", "Sup C"), | |
Person("Steve", "Sup L"), | |
Person("Jen", "Sup L"), | |
Person("Sue", "Sup L"), | |
Person("Rob", "Sup L") | |
] | |
def find_changed_supervisors(yesterday, today): | |
people = {} | |
for person in yesterday: | |
people[person.name] = [person] | |
for person in today: | |
if person.name in people: | |
people[person.name].append(person) | |
else: | |
people[person.name] = [person] | |
super_changes = {} | |
for person_name, person_objects in people.iteritems(): | |
if len(person_objects) != 2: | |
continue | |
yesterday_super = person_objects[0].sup | |
today_super = person_objects[1].sup | |
if yesterday_super == today_super: | |
continue | |
super_change = (yesterday_super, today_super) | |
if super_change not in super_changes: | |
super_changes[super_change] = [] | |
super_changes[super_change].append(person_name) | |
for super_change, person_names in super_changes.iteritems(): | |
print "%s --> %s" % super_change | |
print " ".join(person_names) | |
if __name__ == '__main__': | |
find_changed_supervisors(yesterday, today) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment