Python script to list users and groups

For *nix, you have the pwd and grp modules. You iterate through pwd.getpwall() to get all users. You look up their group names with grp.getgrgid(gid).

import pwd, grp
for p in pwd.getpwall():
    print p[0], grp.getgrgid(p[3])[0]

sh/bash:

getent passwd | cut -f1 -d: | while read name; do echo -n "$name " ; groups $name ; done

the grp module is your friend. Look at grp.getgrall() to get a list of all groups and their members.

EDIT example:

import grp
groups = grp.getgrall()
for group in groups:
    for user in group[3]:
        print user, group[0]