Skip to content

Instantly share code, notes, and snippets.

@jay3686
Created February 13, 2012 04:42
Show Gist options
  • Save jay3686/1813743 to your computer and use it in GitHub Desktop.
Save jay3686/1813743 to your computer and use it in GitHub Desktop.
Python Answer to Embedly's Challenge 2
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