Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Simple recursive sum function | what's the cause of the weird behaviour?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Russel Walker, post: 5103997"] I know this is simple but I've been starring at it for half an hour and trying all sorts of things in the interpreter but I just can't see where it's wrong. def supersum(sequence, start=0): result = start for item in sequence: try: result += supersum(item, start) except: result += item return result It's supposed to work like the builtin sum, but on multidimensional lists and also with the optional start parameter accepting something like an emptylist and so would also works as a robust list flattener. It's just for kicks, I'm not actually going to use it for anything. This works: - - - - - - This does not: - - - - - - - [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Simple recursive sum function | what's the cause of the weird behaviour?
Top