Python error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Python error?

Will python give me a recursion error if i just link a lot of functions? Ex: def a(): b() def b(): a() a() This is just an example. Usually i dony need to do that for infinite number of functions:)

11th Mar 2018, 7:12 AM
Adriel Matei
Adriel Matei - avatar
7 Answers
+ 2
@nick: this is called mutual recursion or cross recursion If you try it, you'll see that the maximum recursion depth is exceeded. Which indicates there IS recursion
11th Mar 2018, 6:42 PM
Amaras A
Amaras A - avatar
+ 4
i didnt know that there is a shuffle method:)
11th Mar 2018, 8:04 AM
Adriel Matei
Adriel Matei - avatar
+ 3
i know,first i was doing return b(), but that didnt worked
11th Mar 2018, 7:30 AM
Adriel Matei
Adriel Matei - avatar
+ 3
so a returns b(x) and b returns a(y) etc. i was using that for shuffleing a card deck. PS sorry for my bad english
11th Mar 2018, 7:45 AM
Adriel Matei
Adriel Matei - avatar
+ 2
I don't understand how it would apply to shuffling a card deck. You could just use a list, import the random class, and use the shuffle method. Something like: from random import shuffle cards = list(range(52)) random.shuffle(cards) If you wanted, you could also use a dictionary to easily label the cards, but since it has an undefined order, you would have to get each key into a list, shuffle them, then reassign them.
11th Mar 2018, 7:55 AM
apex137
apex137 - avatar
+ 1
This wouldn't really be recursion, since the functions aren't calling themselves. This is more of an infinite loop, and it wouldn't cause an error. But you do have to make a condition to exit the infinite loop at some point.
11th Mar 2018, 7:28 AM
apex137
apex137 - avatar
+ 1
Why would you return a function? You could try using b as an argument to a instead. There also is this technique called currying, wherein you nest a function inside another function, so that when you declare the first function, you can use it as the argument to another.
11th Mar 2018, 7:43 AM
apex137
apex137 - avatar