You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This approach uses the [`<str>.translate`][translate] method.
@@ -14,18 +14,18 @@ To create a translation table we use [`str.makestrans`][maketrans].
14
14
15
15
This approach starts with defining a constant of all the lowercase letters in the alphabet.
16
16
Then the function `rotate()` is declared.
17
-
A `translator` variable defined with the value of the `AlPHABET` constant [sliced][slicing] from the key to the end and then sliced from the start to the key.
17
+
A `translator` variable defined with the value of the `ALPHABET` constant [sliced][slicing] from the key to the end and then sliced from the start to the key.
18
18
19
19
This is done so we have 2 strings which are the same but shifted by the key value.
20
-
Say we have the `AlPHABET` constant with the value of `abcdefghijklmnopqrstuvwxyz` and the key is 3.
20
+
Say we have the `ALPHABET` constant with the value of `abcdefghijklmnopqrstuvwxyz` and the key is 3.
21
21
Then the `translator` variable will have the value of `defghijklmnopqrstuvwxyzabc`.
22
22
23
23
`str.translate` is then called on the `text` argument.
24
24
`str.translate` takes a translation table mapping start values to transformed values as an argument.
25
25
To create a translation table, `str.makestrans` is used.
26
26
`makestrans` takes 2 arguments: the first is the string to be translated, and the second is the string the first argument should be translated to.
27
27
28
-
For our solution, the first argument is the `AlPHABET` constant + the `AlPHABET` constant in uppercase.
28
+
For our solution, the first argument is the `ALPHABET` constant + the `ALPHABET` constant in uppercase.
29
29
The second argument is the `translator` variable + uppercase `translator` variable.
30
30
31
31
`str.makestrans` takes the [Unicode][unicode] values of the first argument and maps them to the corresponding Unicode values in the second argument, creating a `dict`.
0 commit comments