0
Counter.update()函數需要兩個參數(數據及其鍵),我提供了兩個參數,但它抱怨提供了三個參數。TypeError:update()需要1到2個位置參數,但給出了3個。
from collections import Counter
InputString1 = input()
InputString2 = input()
Set1 = Counter()
Set2 = Counter()
for i in range(len(InputString1)):
arg1 = InputString1.count(InputString1[i])
Set1 = Set1.update(InputString1[i], arg1)
for i in range(len(InputString2)):
arg2 = InputString2.count(InputString2[i])
Set2 = Set2.update(InputString2[i], arg2)
Temp = Set1
Temp.subtract(Set2)
TotCount = sum(Temp.values())
Temp = Set2
Temp.subtract(Set1)
TotCount = TotCount + sum(Temp.values())
print(TotCount)
Traceback (most recent call last):
File "pallidromemake.py", line 8, in <module>
Set1 = Set1.update(InputString1[i], arg1)
TypeError: update() takes from 1 to 2 positional arguments but 3 were given
您是否正在閱讀正確的文檔:https://docs.python.org/2/library/collections.html#collections.Counter.update? Plus不要將更新調用分配給同一個變量,'update()'返回'None'。 –