gpt4 book ai didi

python - 当第一项包含可变对时可变 rlist(家庭作业)

转载 作者:太空宇宙 更新时间:2023-11-04 05:56:06 24 4
gpt4 key购买 nike

def mutable_pair(x,y):
def get_item(index):
if index == 0:
return x
return y
def set_item(index , val):
nonlocal x,y
if index == 0:
x = val
else:
y = val

def make_dict():
contents = None
def make_rlist(first,rest):
return (first,rest)

def dispatch(message,key,value):
nonlocal contents
if message == 'push_first':
contents = make_rlist(mutable_pair(key, value), contents)
z = make_dict()
z('push_first')(2,4)

我有这个问题,当我尝试运行这段代码时,我得到了下一个错误:

Traceback (most recent call last):
File "C:\Users\Michael\workspace\HomeWork1\src\tests.py", line 35, in <module>
z('push_first')(2,4)
TypeError: 'NoneType' object is not callable:

对我错误的地方进行解释会有所帮助

最佳答案

TypeError: 'NoneType' object is not callable:

make_dict 返回 None,所以 zNonez('push_first') 不会工作。

关于python - 当第一项包含可变对时可变 rlist(家庭作业),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27730993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com