Adding to a linked list
<p>Can someone please tell me why my add function is not working:
(it only adds the first {'a', 3} but not the rest)
thankyou</p>

<pre><code>class Frequency(object):
    """
    Stores a letter:frequency pair.

    &gt;&gt;&gt; f = Frequency('c', 2)
    &gt;&gt;&gt; f.letter
    'c'
    &gt;&gt;&gt; f.frequency
    2
    &gt;&gt;&gt; f
    {c: 2}
    """
    def __init__(self, letter, frequency):
        self.letter = letter
        self.frequency = frequency
        self.next = None

    def __repr__(self):
        return '{%s: %d}' % (self.letter, self.frequency)

class SortedFrequencyList(object):
    """
    Stores a collection of Frequency objects as a sorted linked list.
    Items are sorted from the highest frequency to the lowest.
    """
    def __init__(self):
        self.head = None

    def add(self, letter, frequency):
        """
        Adds the given `letter`:`frequency` combination as a Frequency object
        to the list. If the given `letter` is already in the list, the given
        `frequency` is added to its frequency.

        &gt;&gt;&gt; f = SortedFrequencyList()
        &gt;&gt;&gt; f.add('a', 3)
        &gt;&gt;&gt; f
        ({a: 3})
        &gt;&gt;&gt; f.add('b', 2)
        &gt;&gt;&gt; f
        ({a: 3}, {b: 2})
        &gt;&gt;&gt; f.add('c', 4)
        &gt;&gt;&gt; f
        ({c: 4}, {a: 3}, {b: 2})
        &gt;&gt;&gt; f.add('b', 3)
        &gt;&gt;&gt; f
        ({b: 5}, {c: 4}, {a: 3})
        """

        current = self.head
        found = False
        prev = None

        if self.head is None:
            self.head = Frequency(letter, frequency)
        else:
            while current is not None:
                if current.letter == letter:
                    current.frequency = current.frequency + frequency
                    found = True
                prev = current
                current = current.next


            if found is False:
                while current is not None:
                    if current.frequency &gt; frequency:
                        current.next = Frequency(letter, frequency)

                    elif current.frequency &lt; frequency:
                        temp = prev
                        prev = Frequency(letter, frequency)
                        current = temp

                    prev = current
                    current = current.next
</code></pre>
