News for hackers. Stuff that matters.
Re:Understanding a Python Closure Oddity by Spivak on Monday June 17, 2024 @09:37AM (#40705499)
This is less wat. when you write it like

   eager:
   for item in loop():
      item()

   lazy:
   items = []
   for item in loop():
      items.append(item)

   for item in items:
       item()
Each next() into loop increments a shared counter so when you print it out as you go it 1, 2, 3 but when you print it out once you've called it a bunch is 9, 9, 9.

There are no comments on this comment yet.