Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sort lines by last word
#!/usr/bin/env python
import sys
seperator = " "
def getLastToken(item):
return item.split(seperator)[-1].replace("*", "")
lines = []
for line in sys.stdin:
line = line.rstrip()
lines.append(line)
sorted_lines = sorted(lines, key=getLastToken)
for line in sorted_lines:
print line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment