+ 1

Word matcher,

I once tried a program that, for a given string, it started printing random characters till they match the one I wrote. Like: Input: Hello Print: goej Print: ucjw Print: Hfuo Print: Hcfo Print: Helgo Print: Hello My question is: Do I have to make a list with every character to try to match them, or is there another way to do it? I would like to avoid: chars = ["a", "b", "c"...]

13th Feb 2017, 3:20 AM
Carlos Hidalgo
Carlos Hidalgo - avatar
2 ответов
+ 7
I know a way! use ascii code! 97 - 122 is the lowercase alphabet and 65 - 90 is uppercase use char(number here) to convert a ascii to a regular letter, and ord(character here) to convert to ascii. I'm sure you could come up with a for loop that uses it
13th Feb 2017, 5:54 AM
Ahri Fox
Ahri Fox - avatar
+ 3
Do you want also to avoid: chars = "abcd...yzAB...XYZ" ? Because these are not ugly code themselve, just visually more aggressive in the first case :P ...and the second case is still accessible as an array ^^: for c in chars: if c in mystring: # do your stuff here when find char else: # do your stuff here when you don't
14th Feb 2017, 4:26 AM
visph
visph - avatar