python - How to find when a string's letter matches a another's letter? -
For example, alpha and companies we are dealing with two strings:
alpha = "Abiseediifjiacaijekeelmanopikyuartiuviaksajed" number 12345678901234567890123456 comp = "this is how an example"
I compare comp
and alpha
how do I A new list is available, index = []
, where there is a number or index for each letter in the string.
If the computer index [20, 8, 9, 1 9] ....
Ignore spaces Now
And then what Is it possible for me to use those indexes in the second list?
key = "XPMGTDHLYONZBWEARKJUFSCIQV" Nanblp 12345678901234567890123456
So it looks like the final string: ULYJ ....
And whatever we want to do, it adds empty space to the list of space space, I am pretty sure that I can make it.
Sorry, if it is poorly explained, then hopefully all of you will understand. Thanks for the help and thanks in advance.
string module really useful functionality for this.
import string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" key = "XPMGTDHLYONZBWEARKJUFSCIQV" COMP = TR = string.maketrans (alpha key) Print string.translate "This is an example" (comp.upper () , TR) # - & gt; ULYJ YJ XW TIXBAZT
Comments
Post a Comment