def subset_sum(seq, target):
    left, right = seq[0], seq[1:]
return target in (0, left) or bool(right) and (subset_sum(right, target -
    left) or subset_sum(right, target))

def subset_sum_mem(seq, target, mem=None):
    mem = mem or {}
key = len(seq), target
if key not in mem:
    left, right = seq[0], seq[1:]
mem[key] = target in (0, left) or bool(right) and (subset_sum_mem(right, 
    target - left, mem) or subset_sum_mem(right, target, mem))
return mem[key]
Subset sum recursively in Python