Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib2
- from BeautifulSoup import BeautifulSoup
- html = urllib2.urlopen("http://awoiaf.westeros.org/index.php/List_of_Characters")
- soup = BeautifulSoup(html).find("div", {"id":"bodyContent"})
- names = [link.a.text for link in soup.findAll('li')]
- def average(letter):
- total = 0.0
- for i in names:
- total += i.upper().count(letter.upper())
- return total/len(names)
- freq = {}
- for i in "abcdefghijklmnopqrstuvwxyz":
- freq[i.upper()]=average(i.upper())
- sort = sorted(freq, key=freq.get, reverse=True)
- for i in sort:
- print "* " + i + ": %f" % (freq[i])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement