ipython The special use of the underscore in IPython


from urllib.request import urlopen
from collections import Counter
import re

conn = urlopen('http://textfiles.com/100/dodontae.hum')
lines = conn.readlines()

# readlines() returns byte strings
data = ''.join([line.decode('utf-8') for line in lines]) 

# replace non-letters with a space
re.sub('[^A-Za-z]', ' ', data) 

# condense successive whitespace into a single space
# the underscore retrieves the most recent output 
re.sub('\s+', ' ', _)

# normalize the text by lowercasing and removing leading and trailing whitespace

# split into words on space
words = _.split(' ')

from collections import Counter
word_count = Counter()

for word in words:
    word_count[word[0]] += 1