For recursion, it is frequently simpler to return the new value
def expand(node, hcList):
if node.hasTreasure:
hcList.append(node)
if node.end():
return hcList
return expand(node.next(), hcList)
hcList = expand(startnode, [])
hcList.filter() # not sure why this was in the OP
If your list is very deep, you may have a lot on the stack, but good tail recursion can optimize that away.