Skip to content

Instantly share code, notes, and snippets.

@wolf0403
Created March 20, 2014 00:31
Show Gist options
  • Save wolf0403/9654833 to your computer and use it in GitHub Desktop.
Save wolf0403/9654833 to your computer and use it in GitHub Desktop.
sort "du -h" output.
def cmpsz(s1, s2):
tosz = lambda s: ('KMG'.find(s[-1]), float(s[:-1]) if s[-1] in 'KMG' else float(s))
u1, s1 = tosz(s1)
u2, s2 = tosz(s2)
scmp = cmp(u1, u2)
return scmp if scmp != 0 else cmp(s1, s2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment