Pages

CodeEval Reverse Words

Given a string of words, write a function that returns them in reversed order. This is CodeEval problem #8 that has a trivial Python solution.

This is what we want to get, as a python test:
def test_provided_1(self):
    self.assertEqual('World Hello', solution('Hello World'))
And the core of the solution is a mere one-liner:
' '.join(reversed(line.split()))
We split the line, getting a list of strings, reverse it, and join the result on a blank.

I pushed the complete python script, and even the associated unit test, to GitHub.

No comments:

Post a Comment