Created
June 20, 2011 20:12
-
-
Save alvesjnr/1036461 to your computer and use it in GitHub Desktop.
Introducing mapreduce concptes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
text = """No te amo como si fueras rosa de sal, topacio | |
o flecha de claveles que propagan el fuego | |
te amo como se aman ciertas cosas oscuras, | |
secretamente, entre la sombra y el alma. | |
Te amo como la planta que no florece y lleva | |
dentro de sí, escondida, la luz de aquellas flores, | |
y gracias a tu amor vive oscuro en mi cuerpo | |
el apretado aroma que ascendió de la tierra. | |
Te amo sin saber cómo, ni cuándo, ni de dónde, | |
te amo directamente sin problemas ni orgullo | |
así te amo porque no sé amar de otra manera, | |
sino así de este modo en que no soy ni eres, | |
tan cerca que tu mano sobre mi pecho es mía, | |
tan cerca que se cierran tus ojos con mi sueño. | |
""" | |
def map(key, value): | |
for word in value: | |
yield (word,1) | |
def reduce(key, values): | |
summation = 0 | |
for value in values: | |
if value[0] == key: | |
summation += value[1] | |
return (summation) | |
if __name__=='__main__': | |
""" | |
Attention: case sensitive!!! | |
""" | |
text = text.split() #remove all whitespaces | |
mapped_text = map(None,text) | |
keys = set(text) | |
for word in keys: | |
print word, reduce(word, map(None,text)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment