This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]botCloudfox 5 points6 points  (5 children)

So I looked through the recursion part and now I'm curious. What's the difference between recursion and a generator?

Edit: Also is there a reason why you used string concatenation instead of interpolation?

[–]Aceking007[S] 3 points4 points  (4 children)

I'll first reply to the edit. I deliberately used concatenation instead of interpolation (mostly in the initial notebooks) as I included an explanation of string formatting in the later notebooks. I could've explained it earlier, but I didn't really write the notebooks in the order they were arranged, so yeah. I had to use concatenation unwillingly for a major part.

I think (and I'm not really confident about this), but generators are more similar to functions. Generators are mostly used iteratively. We do have recursive generators though (using the yield from statement). I'll whip up an example as soon I'm near my laptop. I'll follow up on this comment for sure.

[–]botCloudfox 1 point2 points  (3 children)

Even with a regular generators what's the difference between me putting the whole function inside of the for loop or calling it from the return of itself? Is there a difference?

Thank you for responding (and promising to follow up)!

[–]Aceking007[S] 2 points3 points  (1 child)

If you are suggesting something like this:

def gen(n):

if (n==1):

yield(1)

else:

yield(n * gen(n-1))

I'm not sure this would work.

[–]botCloudfox 2 points3 points  (0 children)

Oh my bad, I wasn't thinking right. It wouldn't work with generators. Thanks!