I have been learning Python for a while now. I was browsing old posts in this forum and stumbled across
this thread in which Arevos posted the following code:
def permutations(x):
if len(x) <= 1:
yield x
else:
for i in range(len(x)):
for p in permutations(x[:i] + x[i + 1:]):
yield [x[i]] + p I understand recursion, but what is yield and how does it differ from return? And what is a recursive generator?
Also, I understand the gist of how this function works, but it is more complicated than most recursive functions I have studied. Could someone please explain how this particular function works, especially the last two lines? Thanks.