Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Reverse Words
def reverseTextByWord(line):
arrayOfWords = line.split()
reverseArray = arrayOfWords[::-1]
return " ".join(reverseArray)
def addingCase(n):
return "Case #" + str(n) + ": "
inFile = open("sample.txt", "r")
outFile = open("sample.out", "w")
n = int(inFile.readline())
print "n is ", n
case = 1
while case <= n:
line = inFile.readline()
line_reverse = addingCase(case) + reverseTextByWord(line)
print "line_reverse = ", line_reverse
outFile.write(line_reverse + "\n")
case = case + 1
outFile.close()
inFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment