Re: Top level of a recursive function

2022-12-17 Thread Rob Cliffe via Python-list
On 14/12/2022 13:49, Stefan Ram wrote: I also found an example similar to what was discussed here in pypy's library file "...\Lib\_tkinter\__init__.py": |def _flatten(item): |def _flatten1(output, item, depth): |if depth > 1000: |raise ValueError("nesting too deep i

Re: Top level of a recursive function

2022-12-15 Thread Peter Otten
On 13/12/2022 15:46, Michael F. Stemper wrote: It's easy enough -- in fact necessary -- to handle the bottom level of a function differently than the levels above it. What about the case where you want to handle something differently in the top level than in lower levels? Is there any way to tell

Re: Top level of a recursive function

2022-12-13 Thread Michael F. Stemper
On 13/12/2022 09.03, Stefan Ram wrote: "Michael F. Stemper" writes: def fred(cf,toplevel=True): x = cf[0] if len(cf)>1: if toplevel: return x + fred(cf[1:],False) else: return "(" + x + fred(cf[1:],False) + ")" else: if toplevel: return x else:

Re: Top level of a recursive function

2022-12-13 Thread Chris Angelico
On Wed, 14 Dec 2022 at 05:01, Mats Wichmann wrote: > > On 12/13/22 10:36, Chris Angelico wrote: > > On Wed, 14 Dec 2022 at 03:35, Michael F. Stemper > > wrote: > >> > >> It's easy enough -- in fact necessary -- to handle the bottom > >> level of a function differently than the levels above it. Wh

Re: Top level of a recursive function

2022-12-13 Thread Mats Wichmann
On 12/13/22 10:36, Chris Angelico wrote: On Wed, 14 Dec 2022 at 03:35, Michael F. Stemper wrote: It's easy enough -- in fact necessary -- to handle the bottom level of a function differently than the levels above it. What about the case where you want to handle something differently in the top

Re: Top level of a recursive function

2022-12-13 Thread Chris Angelico
On Wed, 14 Dec 2022 at 03:35, Michael F. Stemper wrote: > > It's easy enough -- in fact necessary -- to handle the bottom > level of a function differently than the levels above it. What > about the case where you want to handle something differently > in the top level than in lower levels? Is the

RE: Top level of a recursive function

2022-12-13 Thread Schachner, Joseph (US)
: Tuesday, December 13, 2022 10:25 AM To: python-list@python.org Subject: Re: Top level of a recursive function Supersedes: r...@zedat.fu-berlin.de (Stefan Ram) writes: >def rest( s ): >return "(" + s[ 0 ] +( rest( s[1:] ) if len( s )> 1 else '' )+ ')' &