Created
October 11, 2015 21:35
-
-
Save stewartpark/40c1f27c9329bf3c8110 to your computer and use it in GitHub Desktop.
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
from __future__ import print_function | |
from collections import OrderedDict | |
N = input() | |
raw_records = map(lambda x: raw_input(), xrange(N)) | |
records = OrderedDict() | |
# Since the syntactic correctness is given in the example, and also the order of the names can be simplified to the length of the name, | |
occurence = lambda x, y: len(x) - len(x.replace(y, '')) | |
order = lambda x: (10 * len(x.split())) - occurence(x, '.') | |
max_order = lambda x, y: x if order(x) > order(y) else y | |
reverse = lambda x: list(reversed(x)) | |
strip_all = lambda x: map(lambda y: y.strip(), x) | |
fix_order = lambda x: ' '.join(strip_all(reverse(x.split(',')))) | |
# Split name:ssn | |
raw_records = map(lambda x: x.split(':'), raw_records) | |
# Comma processing | |
raw_records = map(lambda x: [fix_order(x[0]), x[1]] if ',' in x[0] else x, raw_records) | |
# Assign the highest order names in the dict, with the SSN as a key. | |
map(lambda x: records.__setitem__(x[1], max_order(records.get(x[1], ''), x[0])), raw_records) | |
# Print dictionary | |
map(lambda x: print(records[x] + ':' + x), records.keys()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment