title: How to generate a linked-list from a standard list in Python
body: <p>As part of a bigger project, I'm trying to generate a linked-list from a standard list. I've already looked through some topics regarding this problem on SO (e.g. <a href="https://stackoverflow.com/questions/31553576/converting-a-list-to-a-linked-list">here</a>) but most of codes have much different architecture than mine (linked-list is a class itself). Only the last answer was very similar to my solution.</p>
  
  <p>What I try to accomplish here is to create a generator having, among others, a function creating linked-list from a given input (that's why the structure is rigid here). Also I can't touch <em>ListNode</em> class.</p>
  
  <p>I've tried the following code but it returns only single element linked-list with the last element of the list as a node. </p>
  
  <p>I have a feeling I am close but something is missing. I can create helper functions if that's required but ideally, I would like to avoid it. Has anyone any ideas? Where's the mistake? </p>
  
  <pre><code>class ListNode(object):
      def __init__(self, x):
          self.val = x
          self.next = None
  
  class Creator:
  
      def populate(self, in_list):
          # creating the head node
          out_list = ListNode(in_list[0])
          curr = out_list
  
          # iterating over input list
          for i in in_list[1:]:
              curr = curr.next
              curr = ListNode(i)
  
          return curr
  
  
  # Below the manual approach for a list of four elements/nodes
  # manual_list = ListNode(1)
  # manual_list.next = ListNode(2)
  # manual_list.next.next = ListNode(3)
  # manual_list.next.next.next = ListNode(4)
  
  inputs = [1,2,3,4]
  result = Creator().populate(inputs)
  
  while result:
      print(result.val)
      result = result.next
  </code></pre>
  
  <p>Thank you!</p>