How to get this type of output in python?
Input: 'PythoN Is AwoSoMe'
Output: 'aWOsOmE iS pYTHOn'
Help me to solve that
How to get this type of output in python?
Input: 'PythoN Is AwoSoMe'
Output: 'aWOsOmE iS pYTHOn'
Help me to solve that
Use swapcase()
to swap the cases, split()
to divide the string into a list of words, reversed()
to reverse the order of the words, and join()
to join the list of words back into a single string.
>>> 'PythoN Is AwoSoMe'.swapcase()
'pYTHOn iS aWOsOmE'
>>> 'PythoN Is AwoSoMe'.swapcase().split()
['pYTHOn', 'iS', 'aWOsOmE']
>>> list(reversed('PythoN Is AwoSoMe'.swapcase().split()))
['aWOsOmE', 'iS', 'pYTHOn']
>>> ' '.join(reversed('PythoN Is AwoSoMe'.swapcase().split()))
'aWOsOmE iS pYTHOn'