It's Easy - 487-3279

One way to make a telephone number memorable is to have it spell a memorable word or phrase.

Problem “It’s Easy - 487-3279” located at Peking University.

Solution

""" solution.py """

# usage: python3 solution.py < input

# it's easy 487-3279 problem

import sys


def convert(text):
    """ convert text to regular telephone number """
    ref = {'a': 2, 'b': 2, 'c': 2, 'd': 3, 'e': 3, 'f': 3,
           'g': 4, 'h': 4, 'i': 4, 'j': 5, 'k': 5, 'l': 5,
           'm': 6, 'n': 6, 'o': 6, 'p': 7, 'r': 7, 's': 7,
           't': 8, 'u': 8, 'v': 8, 'w': 9, 'x': 9, 'y': 9}

    t = text.replace('-', '').lower()
    t = ''.join(str(ref.get(i, i)) for i in t)

    return t[:3] + '-' + t[3:]


count = {}

with sys.stdin as infile:
    n = int(infile.readline())

    for _ in range(n):
        raw = infile.readline().strip()
        out = convert(raw)

        i = count.get(out, 0)
        count[out] = i + 1

index = [num for num, i in count.items() if i > 1]
index.sort()

if index:
    for num in index:
        print(num, count[num])
else:
    print('No duplicates.')

Output

310-1010 2
487-3279 4
888-4567 3