python unpacking * is throwing syntax error on leetcode

  algorithm, iterable-unpacking, leetcode, python

I am solving the coin change problem. I run code on jupyter-notebook with the given example on leetcode and it works.

enter image description here

The same code does not work on leetcode. causing syntax error:

enter image description here

Here is the code to copy:

def best_sum(target,nums):
    dp=[None for y in range(target+1)]
    dp[0]=[]
    for i in range(len(dp)):
        if dp[i]!=None:
            for num in nums:
                if i+num<=target:
                    combination=[*dp[i],num]
                    if dp[i+num]==None or len(combination)<len(dp[i+num]):
                        dp[i+num]=combination
    return dp[-1]
best_sum(11,[1,2,5])

Source: Python Questions

LEAVE A COMMENT