26 August 2005

Python Challenge

Challenge: reverse every word in a text file in place (preserving line breaks and word order)

Answer:

for line in open("file_name").read().split('\n'):
print ' '.join(line[::-1].split()[::-1])

1 comment:

davidhill0023 said...
This comment has been removed by a blog administrator.