title: Remove item from list in a for loop
body: <p>I have a <code>for</code> loop in my tkinter window that creates a label and a button for every item of a list. I want the button of a corresponding list-item to remove the item from the list, but no matter what button i click, the last element always gets removed! Can someone please help?</p>
  <p>My code:</p>
  <pre><code>import tkinter
  import ntkutils
  
  list = [1, 2, 3, 4, 5, 6]
  root = tkinter.Tk()
  
  def refresh():
      y = 40
  
      def pressed(i):
          list.remove(i)
          ntkutils.clearwin(root)
          refresh()
  
      for index in list:
          tkinter.Label(text=index).place(x=40, y=y)
          tkinter.Button(text=&quot;-&quot;, command=lambda:pressed(index)).place(x=100, y=y)
          y = y+20
  
  refresh()
  root.mainloop()
  </code></pre>
  <p>PS: <code>ntkutils.clearwin</code> just removes all of the window`s content.</p>