+ 1
How to reverse the string without changing the positions of special characters
Input : b@rd Output : d@rb
1 Resposta
+ 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)