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 = {} |
Andrew M. Kuchling | ac6df95 | 2003-05-13 18:14:25 +0000 | [diff] [blame] | 12 | for filename in files: |
| 13 | suff = getsuffix(filename) |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 14 | if not suffixes.has_key(suff): |
| 15 | suffixes[suff] = [] |
Andrew M. Kuchling | ac6df95 | 2003-05-13 18:14:25 +0000 | [diff] [blame] | 16 | suffixes[suff].append(filename) |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 17 | keys = suffixes.keys() |
| 18 | keys.sort() |
| 19 | for suff in keys: |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 20 | print repr(suff), len(suffixes[suff]) |
Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame] | 21 | |
Andrew M. Kuchling | ac6df95 | 2003-05-13 18:14:25 +0000 | [diff] [blame] | 22 | def getsuffix(filename): |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 23 | suff = '' |
Andrew M. Kuchling | ac6df95 | 2003-05-13 18:14:25 +0000 | [diff] [blame] | 24 | for i in range(len(filename)): |
| 25 | if filename[i] == '.': |
| 26 | suff = filename[i:] |
Tim Peters | 70c4378 | 2001-01-17 08:48:39 +0000 | [diff] [blame] | 27 | return suff |
Guido van Rossum | ec758ea | 1991-06-04 20:36:54 +0000 | [diff] [blame] | 28 | |
| 29 | main() |