Feb-04-2022, 08:30 PM
Can somebody explain to me why in the following code, temp is equal to res after the loop body statement? I have tested it with input [1] and after the loop executes temp is as I said equal to the new res. Also, res = res + temp does not produce the expected [[1],[]] but [[1]].
Can somebody explain this to me as well?
Can somebody explain this to me as well?
def driver(arr): res = [[]] def subsets(arr,res): if arr == []: return subsets(arr[1:],res) temp = res #here temp = [[]] for the inner most function call for subset in res: subset.append(arr[0]) #but here temp = res if one tries for instance the input [1] res = res + temp subsets(arr,res) return res