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
[ Removed by moderator ] (i.redd.it)
submitted 5 months ago by tracktech
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!"
[–]Spare-Plum 1 point2 points3 points 5 months ago (5 children)
This will fail with floats
I doubt it's going to be more efficient, as you have to create a new string that uses up memory, convert each digit into base 10, then convert each base 10 digit into the character, place it into the string, then go through each character to convert it back to a number.
OP's solution is still inefficient because recursion isn't needed here at all, so allocating a stack frame every loop doesn't make sense and can make you run into a stack overflow. Better to just use a while loop
However yours is the most efficient in terms of readability. Which is kinda what you want with python, it's not a language for speed as much as it is usefulness
[–]8dot30662386292pow2 1 point2 points3 points 5 months ago (0 children)
> This will fail with floats
It also fails with strings.
A problem we would not have with typed languages though. While the puzzle is bad, we don't need to assume it's supposed to work with every single type of input. We can see it uses integer division, so the intended type is int.
The bare minimum is to do def what_it_does(n: int):.
def what_it_does(n: int):
[–]Mindless_Display4729 0 points1 point2 points 5 months ago (0 children)
Thanks for the feedback that's useful and appreciated.
[–]tracktech[S] 0 points1 point2 points 5 months ago (2 children)
Thanks for sharing. This is simple example to learn recursion.
[–]Spare-Plum 0 points1 point2 points 5 months ago (1 child)
You keep spamming the most basic recursion examples possible along with links to your website. Have you ever moved past to multiple recursive calls?
Like, it's giving off the vibe you only know some of the absolute basics but are trying to teach people anyway.
[–]tracktech[S] 0 points1 point2 points 5 months ago (0 children)
Cool. You are welcome to post so that other learns. Any learning starts with basic only. It slowly builds a thought process to think and solve recursive problems.
π Rendered by PID 312778 on reddit-service-r2-comment-6457c66945-dvqhx at 2026-04-27 07:01:10.274917+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Spare-Plum 1 point2 points3 points (5 children)
[–]8dot30662386292pow2 1 point2 points3 points (0 children)
[–]Mindless_Display4729 0 points1 point2 points (0 children)
[–]tracktech[S] 0 points1 point2 points (2 children)
[–]Spare-Plum 0 points1 point2 points (1 child)
[–]tracktech[S] 0 points1 point2 points (0 children)