Guido van Rossum | f06ee5f | 1996-11-27 19:52:01 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame] | 2 | |
| 3 | # suff |
| 4 | # |
| 5 | # show different suffixes amongst arguments |
| 6 | |
| 7 | import sys |
| 8 | |
| 9 | def main(): |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 10 | files = sys.argv[1:] |
| 11 | suffixes = {} |
| 12 | for file in files: |
| 13 | suff = getsuffix(file) |
| 14 | if not suffixes.has_key(suff): |
| 15 | suffixes[suff] = [] |
| 16 | suffixes[suff].append(file) |
| 17 | keys = suffixes.keys() |
| 18 | keys.sort() |
| 19 | for suff in keys: |
| 20 | print `suff`, len(suffixes[suff]) |
Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame] | 21 | |
| 22 | def getsuffix(file): |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 23 | suff = '' |
| 24 | for i in range(len(file)): |
| 25 | if file[i] == '.': |
| 26 | suff = file[i:] |
| 27 | return suff |
Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame] | 28 | |
| 29 | main() |