Python Challenge [5]

Using the pickle library.

First, we’ll need to download banner.p and install pickle. This starts the string of having to stumble across an expected library and can be extremely frustrating sometimes.

If you want to read banner.p locally:

import os, pickle
os.chdir(“Documents”)
raw = open(“banner.p”).read()

Otherwise we can take advantage of the urllib library we used in the previous challenge.


import urllib,pickle
url = "http://www.pythonchallenge.com/pc/def/banner.p"
obj=pickle.load(urllib.urlopen(url))
for line in obj:
	    print ''.join(map(lambda pair: pair[0]*pair[1], line))