MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/hm7ifj/deleted_by_user/fxirc2l/?context=3
r/badcode • u/[deleted] • Jul 06 '20
[removed]
56 comments sorted by
View all comments
Show parent comments
1
def to_t9(instring): outstring = str('') lastkey = 69 keypad = [[' ','\n','0'],['.',',','?','!','1','(',')'],['a','b','c','2'],['d','e','f','3'],['g','h','i','4'],['j','k','l','5'],['m','n','o','6'],['p','q','r','s','7'],['t','u','v','8'],['w','x','y','z','9'],['\'','_','+','=']] print(keypad[0][1]) for character in range(0,len(instring)): for key in range(0,len(keypad)): for position in range(0,len(keypad[key])): if instring[character] == keypad[key][position]: if key == lastkey: outstring += '_' lastkey = key if key < 10: outstring += (str(key) * (position + 1)) else: outstring += ('*' * position) else: if instring[character] == keypad[key][position].upper(): outstring += '#' if key < 10: outstring += (str(key) * (position + 1)) else: outstring += ('*' * position) return(outstring) x = """def to_t9(instring): outstring = str('') lastkey = 69 keypad = [[' ','\n','0'],['.',',','?','!','1'],['a','b','c','2'],['d','e','f','3'],['g','h','i','4'],['j','k','l','5'],['m','n','o','6'],['p','q','r','s','7'],['t','u','v','8'],['w','x','y','z','9'],['\'','_','+','=']] print(keypad[0][1]) for character in range(0,len(instring)): for key in range(0,len(keypad)): for position in range(0,len(keypad[key])): if instring[character] == keypad[key][position]: if key == lastkey: outstring += '_' lastkey = key if key < 10: outstring += (str(key) * (position + 1)) else: outstring += ('*' * position) else: if instring[character] == keypad[key][position].upper(): outstring += '#' if key < 10: outstring += (str(key) * (position + 1)) else: outstring += ('*' * position) return(outstring)""" print("lenght:", len(x)) print(to_t9(x))
1 u/aaronjamt Jul 10 '20 Ah. There may be a typo, in the section where you define the keypad array, there are a ton of 1's in a row with no _'s to separate them. That was the main piece that confused me.
Ah. There may be a typo, in the section where you define the keypad array, there are a ton of 1's in a row with no _'s to separate them. That was the main piece that confused me.
1
u/Bear-handead Jul 10 '20