def solution(S): import random import string length_of_s = len(S) S = list(S) for i in range(length_of_s//2): if S[i] == "?" and S[length_of_s - i - 1] != "?": S[i] = S[length_of_s - i - 1] elif S[i] == "?" and S[length_of_s - i - 1] == "?": random_letter = random.choice(string.ascii_letters).lower() S[length_of_s - i - 1] = random_letter S[i] = random_letter elif S[i] != "?" and S[length_of_s - i - 1] == "?": S[length_of_s - i - 1] = S[i] elif S[i] == S[length_of_s - i - 1]: continue else: if S[i] != S[length_of_s - i - 1]: return "NO" # List to string polindrome_string = "".join(S) return polindrome_string