HW4 question 3 main thread
Is it legal to use default parameter like:
def choose_sets(lst, k,templst=)
Or to "wrap" it with another function?
The default value of an argument cannot be a mutable object.
def foo(a=): a.append(1) print(a) foo() foo()
to see why, and run it in Python Tutor - pythontutor.com - to understand why.
instead you need to do:
def foo(a=None): if a == None: a =  a.append(1) print(a) foo() foo()
Can we defind a global var above 'choose_sets' and use it inside the function? thanks:)
I was wondering why should "choose_sets" return [] in case k=0?
if there aren't any sub-groups so why should it return an empty one?
basically i'm requesting a permission to return  in case k=0 (sounds legit, no?)
It appears that there is no difference as far as the result - you get the same behaviour, with an in-place change.
However, if you do
a = a + 
you get a different behaviour.
See here: http://www.pythontutor.com/visualize.html#code=a+%3D+%5B1,2,3,4%5D%0Aa.append(5)%0Ab+%3D+a%0Aa+%2B%3D+%5B6%5D%0Aa+%3D+a+%2B+%5B7%5D&mode=display&cumulative=false&heapPrimitives=false&drawParentPointers=false&textReferences=false&py=3&curInstr=0
The only difference people talk about is in term of efficiency - see discussion on SO: