我真的不知道我出錯的地方。你能幫我麼?將代碼上傳到學校校正系統時,我不斷收到此錯誤。NoneType'object has no attribute'items
-- test: 1
-- failed
-- standard error
Traceback (most recent call last):
File "/proc/self/fd/3", line 6, in <module>
print(sorted(new_dict.items()))
AttributeError: 'NoneType' object has no attribute 'items'
--
-- exit code: 1
(anything other than 0 indicates an error)
(all scripts are killed after three seconds)
-- expected standard output
[(4, 'a'), (10, 'c')]
--
-- actual standard output (max 200 lines)
[(4, 'a'), (10, 'c')]
--
我的代碼是:
import sys
def swap_unique_keys_values(n):
d = {}
for i in n:
if not n[i] in d:
d[n[i]] = i
else:
del d[n[i]]
print(sorted(d.items()))
def main():
swap_unique_keys_values(sys.argv[1])
if __name__ == '__main__':
main()
的輸入是一本字典。任何幫助真的很感激。
回溯返回值不符合您的代碼。 – vaultah