7 Respostas
+ 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
+ 4
i didnt know that there is a shuffle method:)
+ 3
i know,first i was doing return b(), but that didnt worked
+ 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
+ 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.
+ 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.
+ 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.