The example to sort df -h by the percent:
df -h | p 'sorted({}[1:], key=lambda x: int(x.split()[-2][:-1]))'
I saved this as ~/bin/p #!/usr/bin/env python3
import sys
single_line = sys.argv[1] == '-l'
code = ' '.join(sys.argv[2 if single_line else 1:])
if single_line:
for line in sys.stdin:
print(eval(code.format('line.strip()')))
else:
print('\n'.join(eval(code.format('sys.stdin.read().splitlines()'))))I'm not saying I hate Ruby. I just haven't take the time (nor had a reason to, frankly) become a fan the way I have with Python. Being similar languages in terms of both being dynamic, malleable, mostly single threaded and REPL-able they both seem to occupy the same spot in my toolbox.
Not to knock Ruby-the-language, but the one hitch is that Python's ecosystem is quite a bit vaster into fields I don't interact with (biology, physics, etc.) but also with many that I do (numpy/sympy, cli utilities and scripting, opencv, curl bindings). Where I'm at, it's most everyone's secondary or tertiary language.
Nothing against Ruby, it's just circumstance. If anything I might pick it up soon if only to access JRuby/TruffleRuby worlds which are much ahead of Jython/GraalPython.
Oh, except for function calls without (). And I'm not huge on DSLs. They seem icky but I grew to love significant whitespace in Python so maybe I'll grow to love those too.