そのため、リンクされたリストの前にアイテムを挿入しようとしましたが、ある程度は機能しますが、完全には機能しません。これが私がこれまでに持っているものです(LinkedListクラスには他にもメソッドがありますが、問題がなかったので省略しました):
class _Node():
    def __init__(self, data=None, link=None):
        self.data = data
        self.link = link
class LinkedList():
    def __init__(self):
        self.first = None
        self.size = 0
    def insert(self, ind, item):
        if self.first is None:
            self.first = _Node(item)
        elif ind == 0:                   # this is where the problem is. When I try to 
            temp = self.first            # insert a node to the front, it seems to
            temp.link = self.first.link  # forget about the rest of the nodes.
            self.first = _Node(item)
            self.first.link = temp  
        else:
            count = 0
            while count != ind - 1:
                count += 1
                self.first = self.first.link
            self.first.link = _Node(item, self.first.link)
        self.size += 1
私はこれをシェルに持っていると言います:
    >>> L = LinkedList()
    >>> L.insert(0, 5)
    >>> L.insert(1, 10)
    >>> L.insert(0, 20)
    >>> L[0]
    20
    >>> L[1]
    5
    >>> L[2]
    # and here is an error message, it says NoneType object has no attribute 'data'
上記のコードで、私がやろうとしているのは、最初のノード オブジェクトと同一の一時ノード オブジェクトを作成することです。その一時ノードを最初のノード リンクにリンクし、新しいノードを作成し、その新しいノードをリンクします。ノードを一時ノードに追加しますが、これは機能しません。どんな助けでも素晴らしいでしょう、ありがとう!