Python Forum

Full Version: Making list empty after return in function
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
This is probably fine, but ichabod's solution is quadratic time where you probably intend linear time. Here's part of the second solution I was referring to:
def flatten(nested_list, result=None):
    if result is None: result = []
The rest of the body should be the same as your original solution. This supports the same interface as your original solution, except that (as I lamented) someone could pass in the additional parameter.
Pages: 1 2