Removes duplicate alphabetic characters in a keyword (letter is ignored after its first appearance). :param key: Keyword to use :return: String with duplicates removed >>> remove_duplicates('Hello World!!') 'Helo Wrd'
(key: str)
| 1 | def remove_duplicates(key: str) -> str: |
| 2 | """ |
| 3 | Removes duplicate alphabetic characters in a keyword (letter is ignored after its |
| 4 | first appearance). |
| 5 | |
| 6 | :param key: Keyword to use |
| 7 | :return: String with duplicates removed |
| 8 | |
| 9 | >>> remove_duplicates('Hello World!!') |
| 10 | 'Helo Wrd' |
| 11 | """ |
| 12 | |
| 13 | key_no_dups = "" |
| 14 | for ch in key: |
| 15 | if ch == " " or (ch not in key_no_dups and ch.isalpha()): |
| 16 | key_no_dups += ch |
| 17 | return key_no_dups |
| 18 | |
| 19 | |
| 20 | def create_cipher_map(key: str) -> dict[str, str]: |