Given a string, toggle the characters of those words who have all their characters in the same case.
Input : Geeks for Geeks
Output : Geeks FOR Geeks
Explanation: The string contains three words “Geeks”, “for”, “Geeks” out of which the word “for” contains all its characters as lower cases, therefore, toggle the case of the word. Print the remaining characters as it is.
Input : HELLO world
Output : hello WORLD
Consider each word in the string separately. Set two flags, one to check if all the cases of the characters are the same and another to check if the characters are upper case or lower case.
if all the characters are in the same case if all the characters are lower case then convert into upper case else convert into lower case else print the same word
Below is the implementation:
Geeks FOR Geeks
Using Library functions :
We can also use direct library functions to check if individual words are lower or upper.
Geeks FOR Geeks
- Possible Words using given characters in Python
- Python program to count upper and lower case characters without using inbuilt functions
- Toggle case of a string using Bitwise Operators
- Minimum number of operations to move all uppercase characters before all lower case characters
- Python regex to find sequences of one upper case letter followed by lower case letters
- Program to toggle all characters in a string
- Convert characters of a string to opposite case
- Group words with same set of characters
- K length words that can be formed from given characters without repetition
- Print all valid words that are possible using Characters of Array
- Java program to swap first and last characters of words in a sentence
- Lower case to upper case - An interesting fact
- Switch Case in Python (Replacement)
- Python | Convert case of elements in a list of strings
- Python | Convert list of strings and characters to list of characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.