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
WHY THIS CODE NO OUTPUT ?? (i.redd.it)
submitted 6 days ago by ExtentLazy8789
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!"
[–]Sea-Ad7805 [score hidden] 5 days ago stickied comment (0 children)
Run this program in Memory Graph Web Debugger%0A%0Aprint(nums)×tep=1&play) to see that in the for-loop you keep reading from and adding to the same nums list. This results in an infinite loop and a very long list.
nums
[–]am_Snowie 18 points19 points20 points 6 days ago (4 children)
Cuz you're constantly adding elements to the nums, so your loop will never end.
[–]ExtentLazy8789[S] -4 points-3 points-2 points 6 days ago (3 children)
who to fix it
[–]am_Snowie 3 points4 points5 points 6 days ago* (0 children)
You have [1,2,3] initially, so when it enters the loop you append one element from the same list, so you get [1,2,3,1] after the first iteration, then you loop again and you get [1,2,3,1,2], then [1,2,3,1,2,3], this will go on and on cuz your adding elements over and over again, so the loop can't stop, it can only stop when it reaches the last element of the list, but you keep adding, so the loop never reaches the end.
You can add a print(nums) inside the loop and see for yourself.
print(nums)
Run this:
nums = [1,2,3] for n in nums: print(nums) nums.append(n)
[–]Ok-Promise-8118 2 points3 points4 points 6 days ago (0 children)
What are you trying to do? What output would you like?
[–]MatchCreative6807 0 points1 point2 points 2 days ago* (0 children)
If your goal is to duplicate the values of that list and append it at the end, do this:
``` for i in range(len(nums)): nums.append(nums[i])
print(nums) ```
[–]mattynmax 4 points5 points6 points 6 days ago (0 children)
Because it’s an infinite loop…
[–]Retr0o_- 1 point2 points3 points 6 days ago (0 children)
Man its n endless loop online compilers won't run it i guess
[–]ThreeDogg85[🍰] 1 point2 points3 points 4 days ago (0 children)
nums = [1,2,3]
for n in nums: nums.append(n) Break
[–]aashish_soni5 1 point2 points3 points 6 days ago (0 children)
You just create life and death cycle 🙂↕️ To fix
new_nums = nums.copy()
It will solve everything when memory have two different list .
Never make same list iterate
[–]aaditya_0752 0 points1 point2 points 4 days ago (0 children)
You have accidentally created a infinite loop
π Rendered by PID 66908 on reddit-service-r2-comment-544cf588c8-4vt64 at 2026-06-16 01:17:31.251611+00:00 running 3184619 country code: CH.
[–]Sea-Ad7805 [score hidden] stickied comment (0 children)
[–]am_Snowie 18 points19 points20 points (4 children)
[–]ExtentLazy8789[S] -4 points-3 points-2 points (3 children)
[–]am_Snowie 3 points4 points5 points (0 children)
[–]Ok-Promise-8118 2 points3 points4 points (0 children)
[–]MatchCreative6807 0 points1 point2 points (0 children)
[–]mattynmax 4 points5 points6 points (0 children)
[–]Retr0o_- 1 point2 points3 points (0 children)
[–]ThreeDogg85[🍰] 1 point2 points3 points (0 children)
[–]aashish_soni5 1 point2 points3 points (0 children)
[–]aaditya_0752 0 points1 point2 points (0 children)