The stupid question is the question not asked | |
PerlMonks |
Re^4: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)by paddy3118 (Acolyte) |
on Aug 15, 2007 at 08:40 UTC ( [id://632674]=note: print w/replies, xml ) | Need Help?? |
It is sometimes hard to not use ::-1 once learnt, but you can use reversed which makes it clearer:
>>> def reverseWords(word): ... return " ".join( reversed(word.split()) ) ... >>> reverseWords(" one two three four ") 'four three two one' - Paddy
In Section
Meditations
|
|