Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as Python by nrg ( 13 years ago )
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys

current_word = None
current_count = 0
word = None

for line in sys.stdin:
 line = line.strip()
 
 (word, count) = line.split('\t', 1)

 count = int(count)

 # Так как Hadoop сортирует выдачу вывода mapper.py, то данные пиходят к нам в отсортированном порядке
 if current_word == word:
  current_count += count
 else:
  # Если слово поменялось, то выводим результаты предыдущего подсчета 
  if current_word:
   print '%s\t%s' % (current_word, current_count)

  current_word = word
  current_count = count

# В конце цикла нужно вывести результаты подсчета
if current_word == word:
 print '%s\t%s' % (current_word, current_count)

 

Revise this Paste

Your Name: Code Language: