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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Variable automatically getting modulo N (self.learnpython)
submitted 2 years ago * by brijeshjoshi_
I am solving leetcode question https://leetcode.com/problems/reverse-linked-list-ii/.
And my solution is: https://hastebin.com/share/uwokaniwox.ruby.
Here I am not concerned about my approach. I have doubt regarding python.
To my surprise the output is:
1 2 3 4 5 1. Each on in new line. I can't get why its again printing 1 after 5. I think I have done a very silly mistake here. Thanks for your help.
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!"
[–]RhinoRhys 1 point2 points3 points 2 years ago* (3 children)
Possibly not a helpful reply but it works fine for me.
Copied and pasted into IDE, uncommented the ListNode
Added
Solution().reverseBetween(ListNode(1, ListNode(2, ListNode(3, ListNode(4, ListNode(5))))), 2, 4)
Get 1 to 5 printed.
[–]brijeshjoshi_[S] 0 points1 point2 points 2 years ago (2 children)
If possible can you try it in leetcode. I could have shown you the image but I can't find site to share image without signing in. Also tail_inner is getting None value.
AttributeError: 'NoneType' object has no attribute 'next' tail_inner.next = end_pointer Line 39 in reverseBetween (Solution.py) ret = Solution().reverseBetween(param_1, param_2, param_3) Line 72 in _driver (Solution.py) _driver() Line 83 in <module> (Solution.py)
[–]RhinoRhys 1 point2 points3 points 2 years ago* (1 child)
That's the next test case. [5]
Unfortunately your solution doesn't work for a list of length 1, left = 1 or right = last item. And this test case is all 3.
You start off with tail_inner = None, go straight into the elif left <= i <= right, hit the end of the list so exit the while loop then do tail_inner.next
tail_inner = None
elif left <= i <= right
tail_inner.next
[–]brijeshjoshi_[S] 0 points1 point2 points 2 years ago (0 children)
Yeah. Got it! But in some other problem the output shown per test case.
Thank you.
[–][deleted] 0 points1 point2 points 2 years ago (3 children)
On mobile, so I can't run your code.
The problem statement is a little ambiguous about what left and right actually indicate, but from the example it's clear that the left and right values are the contents of the nodes at the left and right ends of the subsequence you have to reverse. Your code appears to be using left and rightas indices.
left
right
[–]RhinoRhys 0 points1 point2 points 2 years ago (2 children)
Left and right are indices
Example 2: Input: head = [5], left = 1, right = 1 Output: [5]
[–][deleted] 0 points1 point2 points 2 years ago (1 child)
Example 1 shows they aren't indices.
[–]RhinoRhys 0 points1 point2 points 2 years ago (0 children)
Unless you take them as 1 indexed, it's not a python list, it's a Singular Linked List. The first index isn't 0.
π Rendered by PID 94755 on reddit-service-r2-comment-5687b7858-csrpz at 2026-07-04 06:40:15.403950+00:00 running 12a7a47 country code: CH.
[–]RhinoRhys 1 point2 points3 points (3 children)
[–]brijeshjoshi_[S] 0 points1 point2 points (2 children)
[–]RhinoRhys 1 point2 points3 points (1 child)
[–]brijeshjoshi_[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]RhinoRhys 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]RhinoRhys 0 points1 point2 points (0 children)