Phrase reversals

From Rosetta Code
Revision as of 06:34, 13 November 2014 by rosettacode>Paddy3118 (New draft task and Python solution.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Phrase reversals is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Given a string of space separated words containing the following phrase:

"rosetta code phrase reversal"
  1. Reverse the string.
  2. Reverse each individual word in the string, maintaining original string order.
  3. Reverse the order of each word of the phrase, maintaining the order of characters in each word.

Show your output here.

Python

<lang python>>>> phrase = "rosetta code phrase reversal" >>> phrase[::-1] # Reversed. 'lasrever esarhp edoc attesor' >>> ' '.join(word[::-1] for word in phrase.split()) # Words reversed. 'attesor edoc esarhp lasrever' >>> ' '.join(word for word in phrase.split()[::-1]) # Word order reversed. 'reversal phrase code rosetta' >>> </lang>