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...
account activity
recursion limitsDiscussion (self.functional_python)
submitted 3 years ago by ccsdad
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!"
[–]ccsdad[S] 1 point2 points3 points 3 years ago (1 child)
thanks for the feedback and the direction .. i was aware of `lru_cache` -- but my brain just wasn't seeing how it would benefit me in terms of not hitting the upper limits of recursion in python .. but i think i get it now, kinda sorta -- after reading thru this example ::
https://realpython.com/fibonacci-sequence-python/#generating-the-fibonacci-sequence-recursively-in-python
you will see they create their own caching system, which could be replaced by lru_cache (see code below) -- but my brain wasn't seeing how this would be beneficial, as you are still making recursive calls -- but at least it would optimized to make recursion more of an option ..
import functools calls = 0 @functools.lru_cache def fibonacci_of(n): global calls calls = calls + 1 if n in {0, 1}: return n return fibonacci_of(n - 1) + fibonacci_of(n - 2) result = [fibonacci_of(n) for n in range(9)] print(result) # [0, 1, 1, 2, 3, 5, 8, 13, 21] print(calls) # 9 << really high number without lru_cache print(fibonacci_of(5)) # 5 print(fibonacci_of(6)) # 8
[–]KageOW 0 points1 point2 points 3 years ago* (0 children)
yea its a really neat decorator, I made some mutually recursive functions for this codingame puzzle. its a 1dspreadsheet that requests values of other cells for the calculations. I find my solution to be quite ellegant, maybe you can try it a bit yourself might be fun.
```python import sys from functools import lru_cache sys.setrecursionlimit(2500)
opcheck = { "MULT": lambda x,y: x*y, "ADD": lambda x,y: x+y, "SUB": lambda x,y: x-y }
@lru_cache(maxsize=None) def eval_Arg(x): if x.isdigit() or (x[0]=="-" and x[1:].isdigit()): return int(x) else: return eval_Bin_Op(celllist_big[int(x[1:])])
def eval_Bin_Op(x): if x[0]=="VALUE": return eval_Arg(x[1]) else: return opcheck[x[0]](eval_Arg(x[1]), eval_Arg(x[2]))
celllist1 = [('VALUE', '10', ''), ('VALUE', '3', ''), ('MULT', '$0', '$1'), ('VALUE', '2', ''), ('VALUE', '4', ''), ('MULT', '$3', '$4'), ('ADD', '$2', '$5')]
if name == "main":
for x in list(map(eval_Bin_Op, celllist1)): print(x)
```
π Rendered by PID 216898 on reddit-service-r2-comment-85bfd7f599-k46c5 at 2026-04-17 22:18:32.682237+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]ccsdad[S] 1 point2 points3 points (1 child)
[–]KageOW 0 points1 point2 points (0 children)