我的程序看起来像
# 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' object has no attribute 'append'
不知道为什么会这样?当我已经在每个j
的开头创建了一个列表时
实际上,您将
None
存储在这里:append()
更改列表并返回None
示例:
然而,
while
循环可以简化为相关问题 更多 >
编程相关推荐