Skip to content

Instantly share code, notes, and snippets.

@klebervirgilio
Created August 29, 2012 16:30
Show Gist options
  • Save klebervirgilio/3515268 to your computer and use it in GitHub Desktop.
Save klebervirgilio/3515268 to your computer and use it in GitHub Desktop.
Reverse words
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()
@klebervirgilio
Copy link
Author

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment