suff.py 510 Bytes
Newer Older
1
#! /usr/bin/env python3
Guido van Rossum's avatar
Guido van Rossum committed
2 3 4 5 6 7 8

# suff
#
# show different suffixes amongst arguments

import sys

9

Guido van Rossum's avatar
Guido van Rossum committed
10
def main():
Tim Peters's avatar
Tim Peters committed
11 12
    files = sys.argv[1:]
    suffixes = {}
13 14
    for filename in files:
        suff = getsuffix(filename)
15 16 17 18
        suffixes.setdefault(suff, []).append(filename)
    for suff, filenames in sorted(suffixes.items()):
        print(repr(suff), len(filenames))

Guido van Rossum's avatar
Guido van Rossum committed
19

20
def getsuffix(filename):
21 22 23
    name, sep, suff = filename.rpartition('.')
    return sep + suff if sep else ''

Guido van Rossum's avatar
Guido van Rossum committed
24

25 26
if __name__ == '__main__':
    main()