Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def parse(people):
- """
- returns a list of tuples; first element in tuple - last name; second element - a dict
- """
- people_dicts = [dict(zip(("first", "last", "email"), person.split())) for person in people.splitlines()]
- return [(d["last"], d) for d in people_dicts]
- def santafy(l):
- def index(i):
- return i % len(l)
- def swap(x, y):
- l[x], l[y] = l[y], l[x]
- for x in range(len(l)):
- if l[index(x)][0] == l[index(x + 1)][0]:
- for xx in range(len(l)):
- if l[index(x + 1 + xx)][0] != l[index(x + 1 + xx + 1)][0]:
- swap(index(x + 1 + xx), index(x + 1 + xx + 1))
- return santafy(l)
- return l
- def report(l):
- def index(i):
- return i % len(l)
- for x in range(len(l)):
- print "{0} is Santa for {1} {2}".format(l[index(x)][1]["email"], l[index(x+1)][1]["first"], l[index(x+1)][1]["last"])
- report(santafy(parse("""Luke Skywalker <luke@theforce.net>
- Leia Skywalker <leia@therebellion.org>
- Harry Potter <harry@hogwarts.com>
- Lily Potter <lily@magic.org>
- Bruce Wayne <bruce@imbatman.com>
- Sarah Connor <sarah@terminator.com>
- John Connor <john@skynet.com>""")))
Add Comment
Please, Sign In to add comment