Results of anonymous function

Question

Given the below code snippet...

functions = []
  for i in range(7):
      functions.append(lambda: i)

  for f in functions:
      print(f())

...share what is printed out. Additionally, share how we could we fix the anonymous (lambda) functions to return what we might have expected.

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now