gpt4 book ai didi

python : AttributeError: 'NoneType' object has no attribute 'append'

转载 作者:太空狗 更新时间:2023-10-29 18:14:47 25 4
gpt4 key购买 nike

<分区>

我的程序看起来像

# global
item_to_bucket_list_map = {}

def fill_item_bucket_map(items, buckets):
global item_to_bucket_list_map

for i in range(1, items + 1):
j = 1
while i * j <= buckets:
if j == 1:
item_to_bucket_list_map[i] = [j]
else:
item_to_bucket_list_map[i] = (item_to_bucket_list_map.get(i)).append(j)
j += 1
print "Item=%s, bucket=%s" % (i, item_to_bucket_list_map.get(i))


if __name__ == "__main__":
buckets = 100
items = 100
fill_item_bucket_map(items, buckets)

当我运行它时,它抛出我

AttributeError: 'NoneType' 对象没有属性 'append'

不确定为什么会这样?当我已经在每个 j

的开头创建列表时

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