Python: Reverse the case of all strings. For those strings, which contain no letters, reverse the strings
Reverse Case or Reverse Strings
Write a Python program to reverse the case of all strings. For those strings, which contain no letters, reverse the strings.
Input: ['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique'] Output: ['CAT', 'CATATATATCTSA', 'ABCDEFHIJKLMNOP', '521581932952421', '', 'FOO', 'UNIQUE'] Input: ['Green', 'Red', 'Orange', 'Yellow', '', 'White'] Output: ['gREEN', 'rED', 'oRANGE', 'yELLOW', '', 'wHITE'] Input: ['Hello', '!@#', '!@#$', '123#@!'] Output: ['hELLO', '!@#', '!@#$', '123#@!']
Visual Presentation:

Sample Solution:
Python Code:
Sample Output:
Original list: ['cat', 'catatatatctsa', 'abcdefhijklmnop', '124259239185125', '', 'foo', 'unique'] Reverse the case of all strings. For those strings which contain no letters, reverse the strings: ['CAT', 'CATATATATCTSA', 'ABCDEFHIJKLMNOP', '521581932952421', '', 'FOO', 'UNIQUE'] Original list: ['Green', 'Red', 'Orange', 'Yellow', '', 'White'] Reverse the case of all strings. For those strings which contain no letters, reverse the strings: ['gREEN', 'rED', 'oRANGE', 'yELLOW', '', 'wHITE'] Original list: ['Hello', '!@#', '!@#$', '123#@!'] Reverse the case of all strings. For those strings which contain no letters, reverse the strings: ['hELLO', '#@!', '$#@!', '!@#321']
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program that toggles the case of each letter in a list of strings and reverses any string containing no alphabetic characters.
- Write a Python program to process a list of strings such that for each string containing letters, the case is reversed, and for strings with only digits or symbols, the string is reversed.
- Write a Python program to alternate between reversing the case and completely reversing the string based on the string’s length.
- Write a Python program to transform a list of strings by inverting the case for letter-containing strings and reversing others, using map() and lambda functions.
Python Code Editor :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Find the first n Fibonacci numbers.
Next: Find the product of the units digits in the numbers.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics