Avatar ·

RecursionError: maximum recursion depth exceeded - how to overcome?

📁 python, вопрос, совет, ии

There is a problem in ; there is its solution, where in elegance Python "defeated" C#, but already at x=512 it throws RecursionError: what do you advise, fathers? How to overcome if I want to calculate for x=1024 for example?

import functools 
from math import sqrt
@functools.lru_cache()
def f(x):
    if x <= 1: return 0
    return 1 + min([ f(m + x // m - 2)  for m in range                    
Avatar ·

E,F,A,B gives a tuple (5,6,1,2), which no longer has any relation to the original variables and is not connected to them in any way.

foo = E,F,A,Bprint(foo)  # => (5, 6, 1, 2)E = -777print(foo)  # still => (5, 6, 1, 2)

The syntax A,B,C,D = is unpacking (in this case of a tuple) — it sequentially assigns to variables the values from a list, tuple, or any other iterable object (you can put = range(4), for example) that comes after the equals sign. And that tuple on the right side no longer has any relation to the original variables.

Log in to leave an answer

Blogs