fl = [25, 33, 287, 454]
palydict = {}
for i in fl:
if str(i) == str(i)[::-1]:
palydict.update(str(i) = "paly")
else:
palydict.update(str(i) = "not paly")
print (palydict)
File "main.py", line 5
palydict.update(str(i) = "paly")
SyntaxError: keyword can't be an expression
有人能解释一下我做错了什么吗?您使用update
不正确。幸运的是,您根本不需要使用它来向字典中添加项。
fl = [25, 33, 287, 454]
palydict = {}
for i in fl:
if str(i) == str(i)[::-1]:
palydict[i] = "paly"
else:
palydict[i] = "not paly"
print palydict