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
- Toggle case of a string using Bitwise Operators
- Python | Words extraction from set of characters using dictionary
- Python program to count upper and lower case characters without using inbuilt functions
- Minimum number of operations to move all uppercase characters before all lower case characters
- Program to toggle all characters in a string
- Python program to convert camel case string to snake case
- Python regex to find sequences of one upper case letter followed by lower case letters
- 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
- Python | Toggle button in kivy using .kv file
- Lower case to upper case - An interesting fact
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
Improved By : Akanksha_Rai