News for hackers. Stuff that matters.
Re:Understanding a Python Closure Oddity by tzs on Monday June 17, 2024 @03:09PM (#40709755)
Another way to use function arguments to fix it is to put another level of function in:

  def loop():
    for number in range(10):

      def make_closure(n):
        def closure():
          return n
        return closure

      yield make_closure(number)

There are no comments on this comment yet.