解包 * 在 leetcode 上抛出语法错误

Yil*_*maz -1 python algorithm iterable-unpacking

我正在解决硬币找零问题。我使用 leetcode 上的给定示例在 jupyter-notebook 上运行代码并且它工作正常。

在此处输入图片说明

相同的代码不适用于 leetcode。导致语法错误:

在此处输入图片说明

这是要复制的代码:

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])
Run Code Online (Sandbox Code Playgroud)

iBu*_*Bug 6

将您的 LeetCode 语言设置为“Python 3”。解包操作符不是 Python 2 中的东西。

如果你不知道,有两种语言python,并python3提供对本文给出了。显然python是指Python 2.7。