|
| 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