I tried to write sorting a list using recursion, I started getting an error TypeError: 'int' object is not callableafter adding a function recursion (before that I used lists of three elements for tests – recursion was not needed) .
def a(mas):
menshe = []
bolshe = []
sorted = []
if len(mas) <= 2:
return mas
else:
a = int(len(mas) // 2)
vibor = mas[a]
del mas[a]
if len(mas) == 2:
for i in mas:
if i < vibor:
menshe.append(i)
else:
bolshe.append(i)
sorted.append(menshe)
sorted.append(vibor)
sorted.append(bolshe)
print(sorted)
else:
a(mas)
Sorry for the shit code, just learning)
Answer 1, authority 100%
The function is named the same as the internal variable.
Thus, when on the last line you “call” a(mas)for the program at that moment ais already reassigned and there is a number (from the line a = int(len(mas) // 2)).
To avoid such errors, please read code formatting conventions and do not use short a, b, i, j, kand other names, but use meaningful names of variables and functions. Functions usually use a verb or an action description.