Pybites Logo

Reverse only letters

Level: Beginner (score: 2)

Given a string, reverse only the English letters (lowercase or uppercase) in the string, leaving all non-English letters and other characters (e.g. numbers) in their original position. 

Example:

>>> from  reverse_letters import reverse_letters
>>> string = "ab-cd"
>>> reverse_letters(string)
'dc-ba'

Example 2:

>>> from  reverse_letters import reverse_letters
>>> string = "ab5DEf"
>>> reverse_letters(string)
'fE5Dba'

Example 3:

>>> from  reverse_letters import reverse_letters
>>> string = "a-bC-dEf-ghIj"
>>> reverse_letters(string)
'j-Ih-gfE-dCba'

Keep calm and code in Python!