+ 1

How to reverse the string without changing the positions of special characters

Input : b@rd Output : d@rb

9th Jan 2022, 5:50 PM
Anna Hari
Anna Hari - avatar
1 Odpowiedź
+ 1
Input = "b@rd" specials = [] InputList = [] for i, x in enumerate(Input): if not x.isalpha(): specials.append((i, x)) else: InputList.append(x) InputList = InputList[::-1] [InputList.insert(x[0], x[1]) for x in specials] Output = "".join(InputList) print(Output)
9th Jan 2022, 6:25 PM
FanYu
FanYu - avatar