Remove duplicate characters, keeping only the first occurrence of each. Args: string: The input string to process. Returns: A new string with duplicate characters removed. Examples: >>> delete_reoccurring_characters("aaabcccc") 'abc'
(string: str)
| 15 | |
| 16 | |
| 17 | def delete_reoccurring_characters(string: str) -> str: |
| 18 | """Remove duplicate characters, keeping only the first occurrence of each. |
| 19 | |
| 20 | Args: |
| 21 | string: The input string to process. |
| 22 | |
| 23 | Returns: |
| 24 | A new string with duplicate characters removed. |
| 25 | |
| 26 | Examples: |
| 27 | >>> delete_reoccurring_characters("aaabcccc") |
| 28 | 'abc' |
| 29 | """ |
| 30 | seen_characters: set[str] = set() |
| 31 | output_string = "" |
| 32 | for char in string: |
| 33 | if char not in seen_characters: |
| 34 | seen_characters.add(char) |
| 35 | output_string += char |
| 36 | return output_string |