Solutions for the Python Challenge

Show possible solutions for: All levels; level: previous, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, next

Possible solution for level 4

URI:
http://www.pythonchallenge.com/pc/def/linkedlist.html
Log-in data:
Username: ; password:
Comment:
Possible Solution:
import urllib, re, time

uri = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=%s"
nothing_rep = "and the next nothing is (\d+)"
nothing = "12345" # You'll later be asked to change this
                  # to "46059" and re-run the script.

while True:
    try:
        source = urllib.urlopen(uri % nothing).read()
        nothing = re.search(nothing_rep, source).group(1)
    except:
        break

    print nothing

(Download this source code.)

Code word for next challenge:
peak

By Holger Thölking, May 29th, 2007.