Re: [Tutor] Recursion

2018-06-18 Thread Alan Gauld via Tutor
On 18/06/18 23:12, Roger Lea Scherer wrote: > My foggy understanding of recursion is probably the reason I can't figure > this out. When turtle draws this program there is an orange line in the > green which I would prefer not to have. I've tried all I could think of, > but can't get the orange

[Tutor] Recursion

2018-06-18 Thread Roger Lea Scherer
My foggy understanding of recursion is probably the reason I can't figure this out. When turtle draws this program there is an orange line in the green which I would prefer not to have. I've tried all I could think of, but can't get the orange line to go away, or maybe more accurately, not to be

Re: [Tutor] Recursion depth exceeded in python web crawler

2018-06-14 Thread Mark Lawrence
On 14/06/18 19:32, Daniel Bosah wrote: I am trying to modify code from a web crawler to scrape for keywords from certain websites. However, Im trying to run the web crawler before I modify it, and I'm running into issues. When I ran this code - *import threading* *from Queue import Queue*

Re: [Tutor] Recursion depth exceeded in python web crawler

2018-06-14 Thread Steven D'Aprano
On Thu, Jun 14, 2018 at 02:32:46PM -0400, Daniel Bosah wrote: > I am trying to modify code from a web crawler to scrape for keywords from > certain websites. However, Im trying to run the web crawler before I > modify it, and I'm running into issues. > > When I ran this code - [snip enormous

[Tutor] Recursion depth exceeded in python web crawler

2018-06-14 Thread Daniel Bosah
I am trying to modify code from a web crawler to scrape for keywords from certain websites. However, Im trying to run the web crawler before I modify it, and I'm running into issues. When I ran this code - *import threading* *from Queue import Queue* *from spider import Spider* *from domain

Re: [Tutor] recursion

2017-05-23 Thread Peter Otten
Alan Gauld via Tutor wrote: > On 23/05/17 06:18, Peter Otten wrote: >> Michael C wrote: >> >>> oh ya, my function does in fact take no input and doesn't change >>> anything, and all i wanted to was to call itself a 2nd time, yes, so I >>> solved it a few hours back ,and it's good enough for me

Re: [Tutor] recursion

2017-05-23 Thread Alan Gauld via Tutor
On 23/05/17 06:18, Peter Otten wrote: > Michael C wrote: > >> oh ya, my function does in fact take no input and doesn't change anything, >> and all i wanted to was to call itself a 2nd time, yes, so I solved it a >> few hours back ,and it's good enough for me for now :) > > Would you mind

Re: [Tutor] recursion

2017-05-23 Thread Michael C
no i don't have a way, it just hasn't happened yet LOL On Mon, May 22, 2017 at 10:18 PM, Peter Otten <__pete...@web.de> wrote: > Michael C wrote: > > > oh ya, my function does in fact take no input and doesn't change > anything, > > and all i wanted to was to call itself a 2nd time, yes, so I

Re: [Tutor] recursion

2017-05-22 Thread Peter Otten
Michael C wrote: > oh ya, my function does in fact take no input and doesn't change anything, > and all i wanted to was to call itself a 2nd time, yes, so I solved it a > few hours back ,and it's good enough for me for now :) Would you mind showing the code? I'd like to see how you avoid

Re: [Tutor] recursion

2017-05-22 Thread Michael C
hi all: oh ya, my function does in fact take no input and doesn't change anything, and all i wanted to was to call itself a 2nd time, yes, so I solved it a few hours back ,and it's good enough for me for now :) Thanks for the response!!! On Mon, May 22, 2017 at 2:16 PM, Alan Gauld via Tutor

Re: [Tutor] recursion

2017-05-22 Thread Alan Gauld via Tutor
On 22/05/17 17:11, Michael C wrote: > I have a function to return (x,y) value, but sometimes it would naturally > unable to return those 2 values properly. I know what recursion is, and I > think all I got to do is to call this function a 2nd time and the problem > would go away. Sorry, but that

[Tutor] recursion

2017-05-22 Thread Michael C
hi all: I have a function to return (x,y) value, but sometimes it would naturally unable to return those 2 values properly. I know what recursion is, and I think all I got to do is to call this function a 2nd time and the problem would go away. How do I do recursion? The function basically look

Re: [Tutor] recursion

2016-02-06 Thread Danny Yoo
On Feb 5, 2016 12:07 AM, "noopy via Tutor" wrote: > > Hi, > > I just cannot get my head around the following code, maybe someone could explain it to me. > > def permutations(items): When trying to understand a function (or in this case, a generator), knowing the types of input

Re: [Tutor] recursion

2016-02-06 Thread Danny Yoo
On Thu, Feb 4, 2016 at 6:03 PM, noopy via Tutor wrote: > Hi, > > I just cannot get my head around the following code, maybe someone could > explain it to me. One thing to note: the function here is a generator, which is itself an intermediate subject that's specific to Python.

[Tutor] recursion

2016-02-05 Thread noopy via Tutor
Hi, I just cannot get my head around the following code, maybe someone could explain it to me. def permutations(items): n = len(items) if n==0: yield [] else: for i in range(len(items)): for cc in permutations(items[:i]+items[i+1:]): yield

Re: [Tutor] recursion

2016-02-05 Thread Ben Finney
noopy via Tutor writes: > But when "for cc in permutations([])" yields an empty list, why does > "for cc in permutations("Z")" then actually have an item so that > "yield [items[i]]+cc" will be executed? Does this help:: >>> i = 1 >>> "Z"[:i] + "Z"[i+1:] 'Z' Can

Re: [Tutor] recursion

2016-02-05 Thread Peter Otten
Ben Finney wrote: > Alan Gauld writes: > >> On 05/02/16 02:03, noopy via Tutor wrote: >> >> > def permutations(items): >> > n = len(items) >> > if n==0: yield [] >> > else: >> >> I assume this bit is clear enough? > > I think it would be clearer

Re: [Tutor] recursion

2016-02-05 Thread Alan Gauld
On 05/02/16 02:03, noopy via Tutor wrote: > I just cannot get my head around the following code, maybe someone could > explain it to me. I'll try but it is a little bit tricky. > def permutations(items): > n = len(items) > if n==0: yield [] > else: I assume this bit is clear

Re: [Tutor] recursion

2016-02-05 Thread Ben Finney
Alan Gauld writes: > On 05/02/16 02:03, noopy via Tutor wrote: > > > def permutations(items): > > n = len(items) > > if n==0: yield [] > > else: > > I assume this bit is clear enough? I think it would be clearer without the needless opaque name ā€˜nā€™.

Re: [Tutor] recursion depth

2014-01-09 Thread Steven D'Aprano
On Wed, Jan 08, 2014 at 06:16:03PM -0500, Dave Angel wrote: On Wed, 8 Jan 2014 16:23:06 -0500, eryksun eryk...@gmail.com wrote: On Wed, Jan 8, 2014 at 3:25 PM, Keith Winston keithw...@gmail.com wrote: I've been playing with recursion, it's very satisfying. However, it appears that even

Re: [Tutor] recursion depth

2014-01-09 Thread Dave Angel
On Thu, 9 Jan 2014 21:41:41 +1100, Steven D'Aprano st...@pearwood.info wrote: I presume that your question is aimed at Keith. Yes, Keith's emails have a HTML part and a text part. A half-decent mail client should be able to read the text part even if the HTML part exists. But I believe

Re: [Tutor] recursion depth

2014-01-09 Thread Keith Winston
On Thu, Jan 9, 2014 at 5:41 AM, Steven D'Aprano st...@pearwood.info wrote: Keith, if you are able, and would be so kind, you'll help solve this issue for Dave if you configure your mail client to turn so-called rich text or formatted text off, at least for this mailing list. Well, hopefully

Re: [Tutor] recursion depth

2014-01-09 Thread Dave Angel
On Thu, 9 Jan 2014 13:02:30 -0500, Keith Winston keithw...@gmail.com wrote: Well, hopefully this is plain text. It all looks the same to me, so if gmail switches back, it might go unnoticed for a while. Sorry for the incessant hassle. That looks great, thanks. -- DaveA

[Tutor] recursion depth

2014-01-08 Thread Keith Winston
I've been playing with recursion, it's very satisfying. However, it appears that even if I sys.setrecursionlimit(10), it blows up at about 24,000 (appears to reset IDLE). I guess there must be a lot of overhead with recursion, if only 24k times are killing my memory? I'm playing with a

Re: [Tutor] recursion depth

2014-01-08 Thread Emile van Sebille
On 1/8/2014 12:25 PM, Keith Winston wrote: I've been playing with recursion, it's very satisfying. However, it appears that even if I sys.setrecursionlimit(10), it blows up at about 24,000 (appears to reset IDLE). I guess there must be a lot of overhead with recursion, if only 24k times are

Re: [Tutor] recursion depth

2014-01-08 Thread Keith Winston
On Wed, Jan 8, 2014 at 3:42 PM, Emile van Sebille em...@fenx.com wrote: Without seeing your code it's hard to be specific, but it's obvious you'll need to rethink your approach. :) Yes, it's clear I need to do the bulk of it without recusion, I haven't really thought about how to do that.

Re: [Tutor] recursion depth

2014-01-08 Thread eryksun
On Wed, Jan 8, 2014 at 3:25 PM, Keith Winston keithw...@gmail.com wrote: I've been playing with recursion, it's very satisfying. However, it appears that even if I sys.setrecursionlimit(10), it blows up at about 24,000 (appears to reset IDLE). I guess there must be a lot of overhead with

Re: [Tutor] recursion depth

2014-01-08 Thread spir
On 01/08/2014 10:11 PM, Keith Winston wrote: On Wed, Jan 8, 2014 at 3:42 PM, Emile van Sebille em...@fenx.com wrote: Without seeing your code it's hard to be specific, but it's obvious you'll need to rethink your approach. :) Yes, it's clear I need to do the bulk of it without recusion,

Re: [Tutor] recursion depth

2014-01-08 Thread Keith Winston
On Wed, Jan 8, 2014 at 4:23 PM, eryksun eryk...@gmail.com wrote: You can create a worker thread with a larger stack using the threading module. On Windows the upper limit is 256 MiB, so give this a try: quite excellent, mwahaha... another shovel to help me excavate out the bottom of my

Re: [Tutor] recursion depth

2014-01-08 Thread Keith Winston
On Wed, Jan 8, 2014 at 5:15 PM, spir denis.s...@gmail.com wrote: Funny and useful exercise in recursion: write a func that builds str and repr expressions of any object, whatever its attributes, inductively. Eg with Hmm, can't say I get the joke. I haven't really played with repr, though I

Re: [Tutor] recursion depth

2014-01-08 Thread Dave Angel
On Wed, 8 Jan 2014 16:23:06 -0500, eryksun eryk...@gmail.com wrote: On Wed, Jan 8, 2014 at 3:25 PM, Keith Winston keithw...@gmail.com wrote: I've been playing with recursion, it's very satisfying. However, it appears that even if I sys.setrecursionlimit(10), it blows up at about

Re: [Tutor] recursion depth

2014-01-08 Thread Keith Winston
On Wed, Jan 8, 2014 at 6:16 PM, Dave Angel da...@davea.name wrote: I can't see the bodies of any of your messages (are you perchance posting in html? ), but I think there's a good chance you're abusing recursion and therefore hitting the limit much sooner than necessary. I've seen some code

Re: [Tutor] recursion surprise

2013-06-08 Thread Marc Tompkins
On Sat, Jun 8, 2013 at 4:52 PM, Jim Mooney cybervigila...@gmail.com wrote: Well, I thought if num 10: return num Was a return statement. Num does become 10. You mean I need more than one? It is, and you actually have more than one. All functions return None, unless you

[Tutor] Recursion always returns None

2012-08-28 Thread Dharmit Shah
Hello, I am trying to do the following : 1) Ask user for the length of the word that he'd like to guess (for hangman game). 2) Pick a random word from /usr/share/dict/words (which I understand is not the best choice for hangman). 3) Call a function that would pick a random word to proceed

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Hugo Arts
On Tue, Aug 28, 2012 at 1:23 PM, Dharmit Shah shahdhar...@gmail.com wrote: Hello, I am trying to do the following : 1) Ask user for the length of the word that he'd like to guess (for hangman game). 2) Pick a random word from /usr/share/dict/words (which I understand is not the best

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Steve Willoughby
On 28-Aug-12 04:23, Dharmit Shah wrote: Hello, I am trying to do the following : 1) Ask user for the length of the word that he'd like to guess (for hangman game). 2) Pick a random word from /usr/share/dict/words (which I understand is not the best choice for hangman). 3) Call a function that

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Dave Angel
On 08/28/2012 07:23 AM, Dharmit Shah wrote: Hello, I am trying to do the following : 1) Ask user for the length of the word that he'd like to guess (for hangman game). 2) Pick a random word from /usr/share/dict/words (which I understand is not the best choice for hangman). 3) Call a

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Dharmit Shah
Hello, @Hugo Arts : Thank you! That was awesome to read. Thanks for the len() suggestion. @ Steve : Thank you. As suggested by Dave Angel, I am going to try the loop. And even before implementing it, I can feel that it's going to be more efficient than recursion. @Dave Angel : Thank you for the

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Mark Lawrence
On 28/08/2012 16:51, Dharmit Shah wrote: @ Steve : Thank you. As suggested by Dave Angel, I am going to try the loop. And even before implementing it, I can feel that it's going to be more efficient than recursion. May I ask why you appear to be concerned with efficiency for a hangman game?

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Alan Gauld
On 28/08/12 16:51, Dharmit Shah wrote: @Dave Angel : Thank you for the loop idea. It didn't strike me at all. For some reason some beginners seem to find recursion a natural pattern. Many others, including quite experienced programmers find it a mind bending concept. But as a general rule,

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Steve Willoughby
On 28-Aug-12 09:03, Mark Lawrence wrote: On 28/08/2012 16:51, Dharmit Shah wrote: @ Steve : Thank you. As suggested by Dave Angel, I am going to try the loop. And even before implementing it, I can feel that it's going to be more efficient than recursion. May I ask why you appear to be

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Steve Willoughby
On 28-Aug-12 09:13, Alan Gauld wrote: On 28/08/12 16:51, Dharmit Shah wrote: @Dave Angel : Thank you for the loop idea. It didn't strike me at all. For some reason some beginners seem to find recursion a natural pattern. There is a certain hey, you can do that? That's cool! factor when you

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Alan Gauld
On 28/08/12 17:34, Steve Willoughby wrote: For some reason some beginners seem to find recursion a natural pattern. There is a certain hey, you can do that? That's cool! factor when you first discover recursion. My point was that it seems to be a natural idea for many beginners, they

Re: [Tutor] Recursion always returns None

2012-08-28 Thread Joel Goldstick
On Tue, Aug 28, 2012 at 5:14 PM, Alan Gauld alan.ga...@btinternet.com wrote: On 28/08/12 17:34, Steve Willoughby wrote: For some reason some beginners seem to find recursion a natural pattern. There is a certain hey, you can do that? That's cool! factor when you first discover recursion.

[Tutor] Recursion - Beginner

2010-05-28 Thread Shawn Blazer
Hello! I'm a high school student, and I'm having some trouble learning recursion in my class... For example: Trace the sequence of recursive calls that glee(2,1) spawns: def glee ( idol , scrub ) : if idol == 0 : return scrub elif idol 0 : return scrub + glee ( idol + 10 , idol % 3 ) else :

Re: [Tutor] Recursion - Beginner

2010-05-28 Thread Emile van Sebille
On 5/28/2010 3:09 PM Shawn Blazer said... Hello! I'm a high school student, and I'm having some trouble learning recursion in my class... For example: Trace the sequence of recursive calls that glee(2,1) spawns: I imagine what you'd need to do is manually follow the code for glee

Re: [Tutor] Recursion - Beginner

2010-05-28 Thread Alan Gauld
Shawn Blazer shawnblaze...@gmail.com wrote Hello! I'm a high school student, and I'm having some trouble learning recursion in my class... For example: Trace the sequence of recursive calls that glee(2,1) spawns: def glee ( idol , scrub ) : if idol == 0 : return scrub elif idol 0 : return

Re: [Tutor] Recursion doubt

2008-04-23 Thread Anshu Raval
: [EMAIL PROTECTED]: [EMAIL PROTECTED]: Re: [Tutor] Recursion doubtCC: tutor@python.org Hi, you are tackling 3 heavy subjects in just 1 go! graphs :a triving math society would approve your choice. But you might start with the *slightly* less difficult challenge: trees. I do not know your math

Re: [Tutor] Recursion doubt

2008-04-23 Thread Kent Johnson
Anshu Raval wrote: But my question would again be how do you know to put square brackets around path in if start == end: return [path] in find_all_paths. I am still puzzled by this. find_all_paths() returns a *list* of paths, even when the result is a single path. Without the

Re: [Tutor] Recursion doubt

2008-04-19 Thread Jos Kerc
Hi, you are tackling 3 heavy subjects in just 1 go! graphs :a triving math society would approve your choice. But you might start with the *slightly* less difficult challenge: trees. I do not know your math/programming background, so the following link can perhaps enlighten you:

[Tutor] Recursion doubt

2008-04-15 Thread Anshu Raval
Hi, At the url http://www.python.org/doc/essays/graphs.html there is some code by Guido Van Rossum for computing paths through a graph - I have pasted it below for reference - Let's write a simple function to determine a path between two nodes. It takes a graph and the start and end nodes as

Re: [Tutor] Recursion limit

2007-02-13 Thread Kent Johnson
Eike Welk wrote: Hello Allan! On Monday 12 February 2007 22:17, Alan Gauld wrote: The figure 999 is interesting. Python has a recursion limit of 1000 levels. Do you by any chance use recursion to call your function? Is the recursion limit hard coded, or can it be changed? It is settable

Re: [Tutor] Recursion limit

2007-02-13 Thread Eike Welk
Thank you! I have a program myself that does a lot of recursion. Regards, Eike. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
Greetings: I'm trying to improve my programming and Python skills. To that end I have implemented a word jumble program as a recursive function: given a string of arbitrary length, return a list of all permutations of the string each character exactly once. In other words:

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Alan Gauld
def permute3 (word): retList=[] if len(word) == 1: # There is only one possible permutation retList.append(word) else: # Return a list of all permutations using all characters retlist = [a list comprehension that calls permute3] retlist += [ word[0] +

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Kent Johnson
Carroll, Barry wrote: permuteList=permute2(word[0:pos]+word[pos+1:len(word)]) # Now, tack the first char onto each word in the list # and add it to the output for item in permuteList: retList.append(word[pos]+item) This could be

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Andrei
Carroll, Barry wrote: Greetings: I'm trying to improve my programming and Python skills. To that end I have implemented a word jumble program as a recursive function: given a string of arbitrary length, return a list of all permutations of the string each character exactly once. In

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread R. Alan Monroe
Unfortunately, I don't understand how list comprehensions work and how to implement them. Can someone point me in the right direction, please. Compare these two pieces of code x=[1,2,3,4] y=[] for eachnum in x: y.append(eachnum * 2) versus x=[1,2,3,4] y = [each * 2 for each in x]

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
28, 2005 3:01 PM To: Carroll, Barry; tutor@python.org Subject: Re: [Tutor] Recursion and List Comprehensions def permute3 (word): retList=[] if len(word) == 1: # There is only one possible permutation retList.append(word) else: # Return a list of all

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
:49 PM To: 'Alan Gauld'; Carroll, Barry; tutor@python.org Subject: RE: [Tutor] Recursion and List Comprehensions Alan et al: After reading the topic you recommended I tried rewriting my permute function as follows: snip ___ Tutor maillist - Tutor

Re: [Tutor] Recursion and List Comprehensions

2005-10-28 Thread Carroll, Barry
Andrei: Date: Sat, 29 Oct 2005 01:13:45 +0200 From: Andrei [EMAIL PROTECTED] Subject: Re: [Tutor] Recursion and List Comprehensions To: tutor@python.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=ISO-8859-1; format=flowed snip There's nothing magic about writing a list

[Tutor] recursion odities accross diferent versions of the 2.4.1 interpreter

2005-07-12 Thread Brian van den Broek
Hi all, I'm playing about with some recursive functions where I am getting near the recursion limit. This caused me to do a test, and I am puzzled by the different results when run in the prompt, IDLE and PythonWin. My simple test code is: c = 0 def recursion_test(): global c