aboutsummaryrefslogtreecommitdiff
path: root/challenge-328/eric-cheung/python/ch-1.py
blob: df35c89b2049dc79268f108fa5e9e29314d9bf00 (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
## strInput = "a?z"  ## Example 1
## strInput = "pe?k"  ## Example 2
strInput = "gra?te"  ## Example 3

arrOutput = []

arrReplaceList = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

for nIndx, charLoop in enumerate(strInput):
    if charLoop != "?":
        arrOutput.append(charLoop)
        continue

    ## print (nIndx, charLoop)

    arrExclude = []
    if nIndx > 0:
        arrExclude.append(strInput[nIndx - 1])

    if nIndx < len(strInput) - 1:
        arrExclude.append(strInput[nIndx + 1])

    arrOutput.append([charSubLoop for charSubLoop in arrReplaceList if not charSubLoop in arrExclude][0])

print ("".join(arrOutput))