Skip to content

Instantly share code, notes, and snippets.

View acrymble's full-sized avatar

Adam Crymble acrymble

  • London
View GitHub Profile
@acrymble
acrymble / frequency-pairs.py
Created July 5, 2011 19:29
Python Frequency Pairs
(192, 'the')
(105, 'i')
(74, 'to')
(71, 'was')
(67, 'of')
(62, 'in')
(53, 'a')
(52, 'and')
(50, 'you')
(50, 'he')
@acrymble
acrymble / stopwords.py
Created July 5, 2011 19:31
Python stopwords
stopwords = ['a', 'about', 'above', 'across', 'after', 'afterwards']
stopwords += ['again', 'against', 'all', 'almost', 'alone', 'along']
stopwords += ['already', 'also', 'although', 'always', 'am', 'among']
stopwords += ['amongst', 'amoungst', 'amount', 'an', 'and', 'another']
stopwords += ['any', 'anyhow', 'anyone', 'anything', 'anyway', 'anywhere']
stopwords += ['are', 'around', 'as', 'at', 'back', 'be', 'became']
stopwords += ['because', 'become', 'becomes', 'becoming', 'been']
stopwords += ['before', 'beforehand', 'behind', 'being', 'below']
stopwords += ['beside', 'besides', 'between', 'beyond', 'bill', 'both']
stopwords += ['bottom', 'but', 'by', 'call', 'can', 'cannot', 'cant']
@acrymble
acrymble / remove-stopwords.py
Created July 5, 2011 19:32
Python Remove Stopwords
# Given a list of words, remove any that are
# in a list of stop words.
def removeStopwords(wordlist, stopwords):
return [w for w in wordlist if w not in stopwords]
@acrymble
acrymble / html-to-freq-2.py
Created July 5, 2011 19:33
Python HTML to frequency pairs 2
# html-to-freq-2.py
import urllib2
import obo
url = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'
response = urllib2.urlopen(url)
html = response.read()
text = obo.stripTags(html).lower()
@acrymble
acrymble / frequency-pairs.py
Created July 5, 2011 19:36
Python Frequency Pairs
(25, 'house')
(20, 'yes')
(20, 'prisoner')
(19, 'mr')
(17, 'man')
(15, 'akerman')
(14, 'mob')
(13, 'black')
(12, 'night')
(11, 'saw')
@acrymble
acrymble / write-html.py
Created July 5, 2011 19:42
Python write HTML
# write-html.py
f = open('helloworld.html','w')
message = """<html>
<head></head>
<body><p>Hello World!</p></body>
</html>"""
f.write(message)
@acrymble
acrymble / write-html-2.py
Created July 5, 2011 19:42
Python Write HTML 2
# write-html-2.py
import webbrowser
f = open('helloworld.html','w')
message = """<html>
<head></head>
<body><p>Hello World!</p></body>
</html>"""
@acrymble
acrymble / write-html-2.py
Created July 5, 2011 19:44
Python Write HTML 2 mac
# write-html-2.py
import webbrowser
f = open('helloworld.html','w')
message = """<html>
<head></head>
<body><p>Hello World!</p></body>
</html>"""
@acrymble
acrymble / string-interpolate.py
Created July 5, 2011 19:46
Python shell string interpolate
frame = 'This smells like a %s'
print frame
-> This smells like a %s
print frame % 'banana'
-> This smells like a banana
print frame % 'pear'
-> This smells like a pear
@acrymble
acrymble / string-interpolate-2.py
Created July 5, 2011 19:47
Python shell string interpolate 2
frame2 = 'These are %s, those are %s'
print frame2
-> These are %s, those are %s
print frame2 % ('bananas', 'pears')
-> These are bananas, those are pears