Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Created February 22, 2018 09:33
Show Gist options
  • Select an option

  • Save jreisinger/8125389436cb20f47fde260327bd0a22 to your computer and use it in GitHub Desktop.

Select an option

Save jreisinger/8125389436cb20f47fde260327bd0a22 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import re
def max_length(strings):
max_len = 0
for s in strings:
if len(s) > max_len:
max_len = len(s)
return max_len
username = {}
with open("/etc/passwd") as f:
for line in f:
line = line.strip()
fields = line.split(":")
user, uid = fields[0], fields[2]
username[int(uid)] = user
for uid in sorted(username, reverse=True):
print("{:{width}} {}".format(
username[uid], uid, width=max_length( username.values() )
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment