aboutsummaryrefslogtreecommitdiff
path: root/challenge-328/sgreen/python/ch-2.py
blob: dff805c0b42d6465af8beb593b86364dedc39fbe (plain)
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
#!/usr/bin/env python3

import sys


def good_string(input_string: str) -> str:
    solution = input_string
    while True:
        for idx in range(0, len(solution)-1):
            char = solution[idx]
            # If the next two letters are the same but different case, remove them
            if ((char.isupper() and solution[idx + 1] == char.lower()) or
                    (char.islower() and solution[idx + 1] == char.upper())):
                solution = solution[:idx] + solution[idx + 2:]
                break
        else:
            # No pairs were removed
            break

    return solution


def main():
    result = good_string(sys.argv[1])
    print('"' + result + '"')


if __name__ == '__main__':
    main()