-4

How to get this type of output in python?

Input: 'PythoN Is AwoSoMe'

Output: 'aWOsOmE iS pYTHOn'

Help me to solve that

wjandrea
  • 28,235
  • 9
  • 60
  • 81
user12498867
  • 1
  • 1
  • 3
  • 1
    Does this answer your question? [better way to invert case of string](https://stackoverflow.com/questions/26385823/better-way-to-invert-case-of-string)/[Swapping uppercase and lowercase in a string](https://stackoverflow.com/q/36247173/4518341) and [How to reverse the order of the words in a string](https://stackoverflow.com/q/34128842/4518341) – wjandrea Jul 18 '20 at 16:42
  • 1
    Please read [Why is "Can someone help me?" not an actual question?](https://meta.stackoverflow.com/a/284237/354577) What have you tried? – ChrisGPT was on strike Jul 18 '20 at 16:43
  • Swapcase is done but how to write 3 words as 1st words and 1st words as 3rd word – user12498867 Jul 18 '20 at 16:44
  • Did you even take a look of the first comment?@user12498867 It says how to reverse the string and also the use of swapcase. The soltution it's literally there. – MrNobody33 Jul 18 '20 at 16:47
  • @MrNobody TBF I edited it after posting it – wjandrea Jul 18 '20 at 17:23

1 Answers1

0

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'
Samwise
  • 68,105
  • 3
  • 30
  • 44