Created
February 13, 2012 04:42
-
-
Save jay3686/1813743 to your computer and use it in GitHub Desktop.
Python Answer to Embedly's Challenge 2
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
import math; | |
import urllib | |
from xml.dom import minidom | |
def std(n): | |
return math.sqrt(sum(map(lambda x: (x - float(sum(n))/ len(n))** 2, n))/len(n)) | |
article = minidom.parse(urllib.urlopen("http://apply.embed.ly/static/data/2.html")).getElementsByTagName("article")[0] | |
tags = (); | |
def decnt(xml,depth): | |
global tags; | |
for node in xml.childNodes: | |
if(node.hasChildNodes): | |
decnt(node,depth + 1); | |
tags += ((node.nodeName,depth),); | |
decnt(article,1); | |
#print map(lambda x: x[1],filter(lambda x: x[0] == u'p',tags)) | |
print std(map(lambda x: x[1],filter(lambda x: x[0] == u'p',tags))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment