1
1
openmpi/orte/test/system/red.py
Ralph Castain 40c2fc5f55 Update the tests, add a couple
This commit was SVN r26379.
2012-05-02 19:00:05 +00:00

39 строки
797 B
Python
Исполняемый файл

#!/usr/bin/env python
from operator import itemgetter
import sys
words = []
cnt = []
# input comes from STDIN
for line in sys.stdin:
# remove leading and trailing whitespace
line = line.strip()
# parse the input we got from mapper.py
word, count = line.split('\t', 1)
# convert count (currently a string) to int
try:
count = int(count)
except ValueError:
# count was not a number, so silently
# ignore/discard this line
continue
# Add the word to the list count times
try:
n = words.index(word)
cnt[n] += count
except ValueError:
words.append(word)
cnt.append(count)
# output the final count
print 'Final word count:'
n=0
for wrd in words:
print '%s\t%d' % (wrd, cnt[n])
n += 1