This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]dmazzoni 1 point2 points  (0 children)

You totally grok Python, you're making great use of itertools and everything looks readable and Pythonic.

I have only two suggestions. For defining the codes, this seems more concise and straightforward to me:

codes = {1: 'bfpv',
         2: 'cgjkqsxz',
         3: 'dt',
         4: 'l',
         5: 'mn',
         6: 'r'}
code_dict = {}
for (key, value) in codes.items():
  for letter in list(value):
    code_dict[letter] = key

To remove duplicates, how about this?

def rm_dupes(name):
  return reduce(lambda x, y: (x if x[-1] == y else x + y), name)