On Sat, Jul 6, 2013 at 10:37 PM, Russel Walker <russ.po...@gmail.com> wrote:
> This works:
> - - - - - -
>>>> x = [[1], [2], [3]]
>>>> supersum(x)
> 6
>>>> supersum(x, [])
> [1, 2, 3]
>>>>
>
>
> This does not:
> - - - - - - -
>>>> x = [[[1], [2]], [3]]
>>>> supersum(x, [])
> [1, 2, 1, 2, 3]
>>>>

You have a problem of specification here. What should supersum do with
the list [1]? Should it recurse into it, or append it as a list? It
can't do both. For a list flattener, you would need to either use
.append for each element you come across, or .extend with each list,
with some kind of check to find whether you should recurse or not.

Still, it's a fun thing to play with. I like code golfing these sorts
of trinketty functions, just for fun :)

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to