【发布时间】:2018-03-26 06:03:37
【问题描述】:
请看看这个程序。
append 函数将列表替换为 None。错误附在下面
class Solution(object):
def isIsomorphic(self, a, b):
ad = {}
bd = {}
if len(a) != len(b):
return False
for i in range(len(a)):
if a[i] in ad:
ad[a[i]] = ad[a[i]].append(i)
else:
ad[a[i]] = [i]
if b[i] in bd:
bd[b[i]] = bd[b[i]].append(i)
else:
bd[b[i]] = [i]
ret = True
for j,k in zip(ad.values(), bd.values()):
if j != k:
return False
return ret
sol = Solution()
print sol.isIsomorphic("ccc", "aab")
错误
ad[a[i]] = ad[a[i]].append(i)
AttributeError: 'NoneType' object has no attribute 'append'
【问题讨论】:
标签: python list dictionary data-structures append