diff options
Diffstat (limited to 'Tools/scripts/suff.py')
-rwxr-xr-x | Tools/scripts/suff.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/Tools/scripts/suff.py b/Tools/scripts/suff.py index 462ec32183..0eea0d7548 100755 --- a/Tools/scripts/suff.py +++ b/Tools/scripts/suff.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # suff # @@ -6,24 +6,21 @@ import sys + def main(): files = sys.argv[1:] suffixes = {} for filename in files: suff = getsuffix(filename) - if suff not in suffixes: - suffixes[suff] = [] - suffixes[suff].append(filename) - keys = sorted(suffixes.keys()) - for suff in keys: - print(repr(suff), len(suffixes[suff])) + suffixes.setdefault(suff, []).append(filename) + for suff, filenames in sorted(suffixes.items()): + print(repr(suff), len(filenames)) + def getsuffix(filename): - suff = '' - for i in range(len(filename)): - if filename[i] == '.': - suff = filename[i:] - return suff + name, sep, suff = filename.rpartition('.') + return sep + suff if sep else '' + if __name__ == '__main__': main() |