Skip to content

Instantly share code, notes, and snippets.

@boppreh
Last active February 9, 2023 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boppreh/3cf5489da92d85f11e152739320d147e to your computer and use it in GitHub Desktop.
Save boppreh/3cf5489da92d85f11e152739320d147e to your computer and use it in GitHub Desktop.
Python implementation of `grep 'lasagna' beef.txt | sort -n`
# Python implementation of
# $ grep 'lasagna' beef.txt | sort -n | uniq
import re
lines = list(set(line for line in open('beef.txt') if 'lasagna' in line))
lines.sort(key=lambda line: int(re.match('\d*', line)[0] or 0))
for line in lines: print(line, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment