-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicate_encode.py
More file actions
40 lines (33 loc) · 850 Bytes
/
Copy pathduplicate_encode.py
File metadata and controls
40 lines (33 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 12 13:46:19 2025
@author: Omnia Agabani
"""
def duplicate_encode(word: str) -> str:
"""
convert a string to a new string where each character in the new string is
"(" if that character appears only once in the original string, or ")"
if that character appears more than once in the original string.
Parameters
----------
word : str
Orignal text
Returns
-------
str
Encoded text
"""
Word = word.lower()
counter = {}
new = ""
for letter in list(Word):
if letter in counter:
counter[letter] += 1
else:
counter[letter] = 1
for letter in list(Word):
if counter[letter] == 1:
new += "("
else:
new += ")"
return new