Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 ( #632674=note: print w/replies, xml ) Need Help??


in reply to Re^3: 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)

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
  • Comment on Re^4: Five Ways to Reverse a String of Words (C#, Perl 5, Perl6, Ruby, Haskell)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://632674]
help
Chatterbox?
[1nickt]: chacham I have wanted to, and dones so, and so stated in a reply, and been roundly downvoted 2-1. (I assume for attempting to censor.)
[1nickt]: pryrt yes, I see. There is no way to differentiate without forcing to a string and all sort of weird stuff. It is enough. User 42 can get creative if s/he wishes.
[chacham]: i sent him a private message expressing my displeasure.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2017-05-24 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?