Prior to having fancy iPhones, teenagers would wear out their thumbs sending SMS
messages on candybar-shaped feature phones with 3x4 numeric keypads.

    ------- ------- -------
    |     | | ABC | | DEF |
    |  1  | |  2  | |  3  |
    ------- ------- -------
    ------- ------- -------
    | GHI | | JKL | | MNO |
    |  4  | |  5  | |  6  |
    ------- ------- -------
    ------- ------- -------
    |PQRS | | TUV | | WXYZ|
    |  7  | |  8  | |  9  |
    ------- ------- -------
    ------- ------- -------
    |     | |space| |     |
    |  *  | |  0  | |  #  |
    ------- ------- -------

Prior to the development of T9 (predictive text entry) systems, the method to
type words was called "multi-tap" and involved pressing a button repeatedly to
cycle through the possible values.

For example, to type a letter `"R"` you would press the `7` key three times (as
the screen display for the current character cycles through `P->Q->R->S->7`).  A
character is "locked in" once the user presses a different key or pauses for a
short period of time (thus, no extra button presses are required beyond what is
needed for each letter individually). The zero key handles spaces, with one press of the key producing a space and two presses producing a zero.

In order to send the message `"WHERE DO U WANT 2 MEET L8R"` a teen would have to
actually do 47 button presses.  No wonder they abbreviated.

For this assignment, write a module that can calculate the amount of button
presses required for any phrase. Punctuation can be ignored for this exercise. Likewise, you can assume the phone doesn't distinguish between upper/lowercase characters (but you should allow your module to accept input in either for convenience).

Hint: While it wouldn't take too long to hard code the amount of keypresses for
all 26 letters by hand, try to avoid doing so! (Imagine you work at a phone
manufacturer who might be testing out different keyboard layouts, and you want
to be able to test new ones rapidly.)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def presses(phrase):
	

Solutions:
BUTTONS = ['1', 'abc2', 'def3', 'ghi4', 'jkl5', 'mno6', 'pqrs7', 'tuv8', 'wxyz9', '*', ' 0', '#']

def presses(phrase):
	return sum((1 + button.find(c) for c in phrase.lower() for button in BUTTONS if c in button))


def presses(phrase):
	x = 0
	for letter in phrase:
		if letter.lower() in list('1*#adgjmptw '):
			x += 1
		elif letter.lower() in list('0behknqux'):
			x += 2
		elif letter.lower() in list('cfilorvy'):
			x += 3
		elif letter.lower() in list('234568sz'):
			x += 4
		elif letter.lower() in list('79'):
			x += 5
	return x


buttons = ['1', 'abc2', 'def3', 'ghi4', 'jkl5', 'mno6', 'pqrs7', 'tuv8', 'wxyz9', '*', ' 0', '#']

def getPresses(c):
	for button in buttons:
		if c in button:
			return button.index(c) + 1
	return 0

def presses(phrase):
	return sum((getPresses(c) for c in phrase.lower()))


presses = lambda s: sum(((c in b) * (1 + b.find(c)) for c in s.lower() for b in '1,abc2,def3,ghi4,jkl5,mno6,pqrs7,tuv8,wxyz9,*, 0,#'.split(',')))


def presses(phrase):
	numbers = ['*', '#', '1', 'ABC2', 'DEF3', 'GHI4', 'JKL5', 'MNO6', 'PQRS7', 'TUV8', 'WXYZ9', ' 0']
	print(phrase)
	phrase = phrase.upper()
	result = 0
	for letter in phrase:
		for n in numbers:
			if letter in n:
				result = result + n.index(letter) + 1
	return result


layout = [' 0', '1', 'abc2', 'def3', 'ghi4', 'jkl5', 'mno6', 'pqrs7', 'tuv8', 'wxyz9']
D_LAYOUT = {l: i + 1 for touch in layout for (i, l) in enumerate(touch)}
DEFAULT = 1

def presses(phrase):
	return sum((D_LAYOUT.get(l, DEFAULT) for l in phrase.lower()))


def presses(phrase):
	return sum(map(int, phrase.upper().translate(str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZ *#1234567890', '123123123123123123412312341111444445452'))))


def presses(phrase):
	phrase = phrase.upper()
	counter = 0
	s = set(phrase)
	alphabet = [chr(x) for x in range(65, 91)]
	for x in range(10):
		if x != 1:
			result = (3, 0, 4)[(not x) + (x in [7, 9]) * 2]
			part = alphabet[:result] or [' ']
			part.append(str(x))
			alphabet = alphabet[result:]
			for (i, c) in enumerate(part, 1):
				if c in s:
					res = phrase.count(c)
					counter += res * i
					s.remove(c)
		else:
			for ch in ['1', '*', '#']:
				counter += 1 * phrase.count(ch)
	return counter


def presses(phrase):
	dict_1 = {'1': 1, 'A': 1, 'B': 2, 'C': 3, '2': 4, 'D': 1, 'E': 2, 'F': 3, '3': 4, 'G': 1, 'H': 2, 'I': 3, '4': 4, 'J': 1, 'K': 2, 'L': 3, '5': 4, 'M': 1, 'N': 2, 'O': 3, '6': 4, 'P': 1, 'Q': 2, 'R': 3, 'S': 4, '7': 5, 'T': 1, 'U': 2, 'V': 3, '8': 4, 'W': 1, 'X': 2, 'Y': 3, 'Z': 4, '9': 5, '*': 1, ' ': 1, '0': 2, '#': 1}
	s = 0
	for x in phrase:
		if x.upper() in dict_1:
			s += dict_1[x.upper()]
	return s