![]() ![]() Your alphabet could just be string.ascii_lowercase instead of that list. Then, you construct the result by calling ''.join(…). Therefore, = is a relatively expensive operation and should be avoided.Ī better alternative would be to build a list (by appending or using a list comprehension). Every time you call = on a string, it allocates a new string and fills it with the old content and the new ending. Why do you want to disallow certain characters? If digits and spaces are to be passed through unmodified, why shouldn't the same be true of punctuation? Efficiency Then, you would call print(shift(input("Input message you would like encrypted:\n"), -1)) Shift would be a better as a pure function: it should accept the message as one of its parameters (instead of prompting for it) and return the enciphered result (instead of printing it). A better name would be character, char, or just c. ![]() Letter might not be a letter of the alphabet. Of course, that means that the elif letter.isnumeric() and the else branches are unreachable.ĭid you mean to write this instead? elif letter in ' \t\n': For the record, the string consisting of the two characters / and t is always True, and the two-character string '/n' can never appear within a one-character string. The rest of the expression doesn't matter due to short-circuit evaluation of or. ![]() letter.isalpha() is false), this condition always evaluates to True, because the space character is a non-empty string. Provided that execution reaches that point (i.e. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |