Ctrl K

Mirror the Letters Only

Easy
You are given a string text. Reverse the order of its English letters (lowercase and uppercase), while every other character, such as digits, punctuation and dashes, stays exactly where it was. In other words, if you read off just the letters of the result, they spell the original letters backwards, and each non-letter keeps its position. Return the resulting string.
Example 1
text='no-3-way' → 'ya-3-won'

The letters n o w a y read backwards are y a w o n and fill the letter slots, while the dashes and the 3 stay put: ya-3-won.

Example 2
text='Hi!Bob?' → 'bo!BiH?'

The letters H i B o b reversed are b o B i H; the ! and ? keep their positions: bo!BiH?.

Example 3
text='7+8=15' → '7+8=15'

There are no letters at all, so the string is unchanged.

Constraints
  • 1 ≤ text.length ≤ 100
  • text consists of printable ASCII characters (codes 32 to 126)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWhere the Fragment Starts EasyMirror Phrase Check EasySame When Flipped EasyFlip the Characters in Place EasyMirror the Vowels Easy
loading Python…
Input
text='no-3-way'
Expected
'ya-3-won'

Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.