what's going on here?

Ant antroy at gmail.com
Tue Apr 4 04:25:39 EDT 2006


You are along the right lines. Try printing out the content of each URL
- one of the pages will match your expression, but has additional
instructions... I think you are reaching the end of their false trail
when you get None returned from the url.

The set of pages themselves are the linked list - each contains a
reference to the next element in the sequence. You don't need one to
solve the problem, the problem *is* the linked list!

An example of a linked list in Python is the following if you are
interested:


class Element (object):
    next = None
    def __init__(self, content):
        self.content = content

class LinkedList (object):
    first = None
    last = None

    def add(self, item):
            elmnt = Element(item)
            if not self.first:
                self.first = elmnt
            if self.last:
                self.last.next = elmnt
            self.last = elmnt
    def __iter__(self):
        current = self.first
        while current:
            yield current.content
            current = current.next

ll = LinkedList()

for i in range(10):
    ll.add(i)

for x in ll:
    print "Res: %s" % x




More information about the Python-list mailing list