Skip to content

Instantly share code, notes, and snippets.

@gsiegman
Created December 16, 2009 21:14
Show Gist options
  • Save gsiegman/258182 to your computer and use it in GitHub Desktop.
Save gsiegman/258182 to your computer and use it in GitHub Desktop.
phone_char_mappings = {
'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',
'1': '1', '2': '2', '3': '3',
'4': '4', '5': '5', '6': '6',
'7': '7', '8': '8', '9': '9',
'0': '0'
}
def alpha_phone_to_numeric(phone_number):
return "".join([_convert_phone_char(char) for char in list(phone_number)])[:10]
def _convert_phone_char(char):
if char in phone_char_mappings:
return phone_char_mappings[char]
else:
return ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment