Custom Search

Tuesday, September 21, 2010

python Passing List as default argument to function problem and solutions


def foo(self, matrix_order, matrix_dict, list):

so if you call it multiple times, each time receives the exact same list
default args are only initialized once

------ Solution

def foo(self, matrix_order, matrix_dict, list=None):
if list is None:
list = [[], [], []]

No comments:

Post a Comment