title: Can we insert elements into a linked list using for-loop in python?
body: <p>I implemented a singly linked list like</p>
  <pre><code>class LinkList:
      def __init__(self):
          self.head = None 
  
  class Node:
       def __init__(self, val=0):
          self.val = val
          self.next = None
  </code></pre>
  <pre><code>a = [2, 5, 6, 3, 5, 6, 9]
  </code></pre>
  <p>I was wondering if we can insert each element of the above list using a <code>for</code>-loop into the linked list.</p>
  <p>I tried to do so, but it is not adding all values to the list. Here is my attempt:</p>
  <pre><code>a = [2, 5, 6, 3, 5, 6, 9]
  l.head = Node(a[0])
  l.head.next = Node(a[1])
  for i in range(1, len(a) - 1):
      Node(a[i]).next = Node(a[i + 1])
  </code></pre>
  <p>When after running this, I print the linked list, it only outputs:</p>
  <pre><code>2
  5
  </code></pre>
  <p>How can this be done right?</p>