Skip to content

Instantly share code, notes, and snippets.

@stewartpark
Created October 11, 2015 21:35
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 stewartpark/40c1f27c9329bf3c8110 to your computer and use it in GitHub Desktop.
Save stewartpark/40c1f27c9329bf3c8110 to your computer and use it in GitHub Desktop.
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