-1
I need to do a function that receives a string composed of digits between 2-9 and that the output are letters, that is, basically the function will work as a keyboard of a mobile phone, where the number '2' will match the 'A', the '22' will match the 'B', until 9999 matches Z. For example:
>>> def teclas('22 2 333 33')
"CAFE"
The values entered in the arguments can "turn around", in the sense that if '2222' is inserted, the letter will return to 'A', '22222' the letter will be 'B', etc. As it works on a keystroke mobile phone. Right now I have a dictionary where I assign all the numbers to the corresponding letters like this:
dic={'2':'A', '22':'B', '222':'C', '3':'D'....}
My doubt is how I do so that in case it is inserted '2222' as argument, it is assigned again the value 'A' (I do not know how I do the program "go around").
Welcome to the Sopt community. Wasn’t it clear to me, reading numbers won’t be a direct dictionary? In case, provide '2222' will be the same as provide '2' and provide '22222' will be the same as provide '22'?
– Rubico
Exactly, if we imagine that we are typing on a mobile phone with keys, staying to click on the '2' key repeatedly will cause the letters to change consecutively, in the program this is what has to happen, in case of being entered the value '2222' read back as letter 'A'.
– Stagg
Ah! Do you want to make a mobile keyboard? Then I think your model is wrong. You should have a dic for each key. I will propose an answer.
– lpacheco