New submission from Vincent Liang <shenhen...@qq.com>:
Strange behavior is found when lambda is used inside for-loop. code:(same as attached file) # begin of CODE def aa(x): print("aa") def bb(x): print("bb") namefun = [ ("a", aa), ("b", bb), ] name2fun = {} for name, fun in namefun: name2fun[name] = lambda x: fun(x) # issue happened when calling lambda name2fun["a"](1) name2fun["b"](1) # end of CODE output: bb bb expected output: aa bb ---------- components: Interpreter Core files: test8.py messages: 403899 nosy: vincent7f priority: normal severity: normal status: open title: lambda issue in for-loop type: behavior versions: Python 3.10, Python 3.9 Added file: https://bugs.python.org/file50357/test8.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue45469> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com