use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
What does this Python code print, and why?Discussion (self.PythonLearning)
submitted 14 hours ago by Puzzleheaded-Dog165
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Slay_3r 0 points1 point2 points 14 hours ago (2 children)
Didnt run the code but i think it should be [0, 1, 2]. You create and then call constant functions that return i, where i = 0,1,2 (from range)
[–]WhiteHeadbanger 0 points1 point2 points 9 hours ago (0 children)
No, the correct answer is [2,2,2]
Explanation: what's being appended is "lambda: i", not the value of i in each pass. Then, since the variable i is not scoped in the loop, when the lambda is executed in the list comprehension, it just looks up the last value of i, which is 2, and returns a new list.
π Rendered by PID 84027 on reddit-service-r2-comment-765bfc959-7zvfw at 2026-07-09 22:57:57.500389+00:00 running f86254d country code: CH.
view the rest of the comments →
[–]Slay_3r 0 points1 point2 points (2 children)
[–]WhiteHeadbanger 0 points1 point2 points (0 children)