Created
August 29, 2012 16:30
-
-
Save klebervirgilio/3515268 to your computer and use it in GitHub Desktop.
Reverse words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
test_cases = open(sys.argv[1], 'r') | |
for test in test_cases: | |
result = test.split(' ') | |
result.reverse() | |
index, buf = 0, '' | |
for word in result: | |
index+=1 | |
buf += word.replace('\n','') | |
if index == 2: | |
print buf | |
buf='' | |
else: | |
buf+=' ' | |
test_cases.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
by @leobragatti
import sys
test_cases = open(sys.argv[1], 'r')
for test in test_cases:
result = test.split(' ')
result.reverse()
print " ".join(result)
test_cases.close()