[Tutor] RE: Tutor digest, Vol 1 #363 - 6 msgs

Carlos Angeles cangeles@mail.com
Mon, 17 Jul 2000 19:35:16 -0400 (EDT)


------Original Message------
From: Daniel Yoo <dyoo@hkn.EECS.Berkeley.EDU>
To: Carlos Angeles <cangeles@mail.com>
Sent: July 17, 2000 9:36:22 PM GMT
Subject: Re: [Tutor] RE: Tutor digest, Vol 1 #363 - 6 msgs


> Have you tried making strip recursive?  Change it to look like this:
> 
> def strip(input):
> ____while (len(input) > 0):
> ________if input[0] == ">" or input [0]==" ":
> ____________input = strip(input[1:])
> ____return input
> 
> I didn't have a chance to test it with a file.  I just did a quick
> check in IDLE and it stripped off the leading "> > > >"'s that if fed
> it.  Let me know if that works.

This is dangerous because it runs into a similar problem if the input line
contains something like "||| Another infinite loop |||" or some other
non-numeric characters.  In fact, it only works if your line consists of
nothing but '>' or ' ' characters!  You probably meant to put:


###
def strip(input):
  if input[0] == ">" or input [0]==" ":
    input = strip(input[1:])
  return input
###

instead.  Be careful with mixing recursion with 'while' statement; believe
me, I've had plenty of bad experiences with this bug.

Daniel,
The way you suggestion is the way I tried it in IDLE but I wasn't sure how an empty line would be treated.  Now that I think about it more a blank line wouldn't meet the two if's so it would skip the recursion and return the empty line.

Is my thinking correct?

Carlos

______________________________________________
FREE Personalized Email at Mail.com
Sign up at http://www.mail.com/?sr=signup