I just learned closures and I discovered that:
from threading import Thread
from time import sleep
def call(time,f):
def caller():
sleep(time)
f()
Thread(target=caller).start()
def func():
for i in range(1,6):
call(i,lambda: print(i))
func()
And that code writes five '5' onto the screen. Thats amazing. And I understand that it is because of the same memory addresses. Now I want to know is there are any good and pythonic way of make that function write 1,2,3,4,5 instead of 5,5,5,5,5. For example you can do it in js by using let keyword.