Permalink
Browse files

occurs.py: shorten using some tricks from Tom Lynn.

  • Loading branch information...
1 parent 1b59a01 commit 91b856c5b36d04cad47e079b60dce9e4898c1ae4 @rrthomas committed Sep 7, 2012
Showing with 4 additions and 9 deletions.
  1. +4 −9 occurs.py
View
@@ -24,7 +24,7 @@
parser.add_argument('-s', '--symbol', metavar='REGEXP', default='[^\W\d_]+',
help='symbols are given by REGEXP')
parser.add_argument('-V', '--version', action='version',
- version='%(prog)s 0.9 (27 Sep 2011) by Reuben Thomas <rrt@sc3d.org>')
+ version='%(prog)s 0.91 (7 Sep 2012) by Reuben Thomas <rrt@sc3d.org>')
parser.add_argument('file', metavar='FILE', nargs='*')
args = parser.parse_args()
@@ -40,16 +40,11 @@
# Process input
freq = Counter()
-args.file = args.file or ['-']
-for i, f in enumerate(args.file):
- for line in fileinput.input(files=(f,)):
- freq.update(pattern.findall(line))
+for line in fileinput.input(files=args.file or ['-']):
+ freq.update(pattern.findall(line))
# Write output
for s in freq:
- print(s, end='')
- if not args.nocount:
- print(' {}'.format(freq[s]), end='')
- print('')
+ print(s + ('' if args.nocount else ' {}'.format(freq[s])))
if not args.nocount:
print("Total symbols: {}".format(len(freq)), file=sys.stderr)

0 comments on commit 91b856c

Please sign in to comment.