Reducing repetitiveness has made this code harder to read. I had to think about what it is doing. It might be slightly faster, but in my opinion it is not worth it.
--- Joseph S. Teledyne Confidential; Commercially Sensitive Business Data -----Original Message----- From: Stefan Ram <r...@zedat.fu-berlin.de> Sent: Tuesday, December 13, 2022 10:25 AM To: python-list@python.org Subject: Re: Top level of a recursive function Supersedes: <reduce-20221213161...@ram.dialup.fu-berlin.de> r...@zedat.fu-berlin.de (Stefan Ram) writes: >def rest( s ): > return "(" + s[ 0 ] +( rest( s[1:] ) if len( s )> 1 else '' )+ ')' >def nest( s ): > return( s[ 0 ] if s else '' )+( rest( s[1:] )if len( s )> 1 else '' ) Below, I have tried to reduce repetitiveness a bit. (PS: Now, one "if" remains; less ifs are not possible in the case of controlled recursion.) def rest( s ): return '(' + nest( s )+ ')' def nest( s ): return s[ :1 ]+( rest( s[ 1: ])if s[ 1: ]else '' ) fred = nest -- https://mail.python.org/mailman/listinfo/python-list