in reply to Re: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
in thread Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
TMTOWTDI even in Python, these days:
def reverseWords(words): return ' '.join([word for word in words.split()][::-1])
I'd probably tweak it a bit in real-world code, though. Generators and list comprehensions make me go cross-eyed sometimes.
Update: Adjusted the code to match the full goal.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
by ambrus (Abbot) on Dec 12, 2006 at 22:03 UTC | |
|
Re^3: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)
by Anonymous Monk on Jun 05, 2007 at 13:41 UTC | |
by paddy3118 (Acolyte) on Aug 15, 2007 at 08:40 UTC |