Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 352de03

Browse files
Create duplicate_encoder
1 parent 6ef5906 commit 352de03

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎code_wars/duplicate_encoder

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
The goal of this exercise is to convert a string to a new string where each character in the new string is
3+
"(" if that character appears only once in the original string,
4+
or ")" if that character appears more than once in the original string.
5+
Ignore capitalization when determining if a character is a duplicate.
6+
'''
7+
8+
def duplicate_encode(word):
9+
wordlist = []
10+
word = word.lower()
11+
newlist = []
12+
for i in word:
13+
wordlist += i
14+
for i in wordlist:
15+
if wordlist.count(i) > 1:
16+
newlist.append(")")
17+
else:
18+
newlist.append("(")
19+
return "".join(str(i) for i in newlist)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /