It's simple if you read the purpose and code in order.
word = tuple(str(password)) tuples
word will be
('h', ', 'k', 'n', 'u', 'd', ', 'x', 'n', 't').
for word in dictionary.keys(): patrols the key value of
dictionary and the key is substituted for
That is, loop around
"a" and loop around
"b"... loops for all keys for
However, the value of
word that we tupled earlier at this time will disappear due to the for statement, right?
What you want to do is find each letter of
word with a key in
dictionary and combine it into the original sentence. Therefore, the tuple value must not disappear.
And in the for statement, you should not go around with the key of
dictionary but you should go around with the letter of
Therefore, if you have a tupled
word and write a for statement to go around the loop, you can find it in
dictionary for each letter.
But then you just find each letter, not the original sentence.
You can combine the characters found in
dictionary into strings as follows:
As a result,
"hknud xnt" is converted to
"i love you".
© 2022 pinfo. All rights reserved.