Skip to content

Instantly share code, notes, and snippets.

@douzo
douzo / reverse_alphabets.py
Last active July 12, 2023 04:59
in the given string, reverse only the alphabets while keeping the integers in its original position
def reverse_alphabets(string):
# Separate alphabets and digits
alphabets = []
digits = []
for char in string:
if char.isalpha():
alphabets.append(char)
else:
digits.append(char)