Skip to content

Instantly share code, notes, and snippets.

Created July 26, 2014 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/22f3b363d834e2bfa818 to your computer and use it in GitHub Desktop.
Save anonymous/22f3b363d834e2bfa818 to your computer and use it in GitHub Desktop.
StackOverflow question #24975218
#!/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)
print
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