0

The Counter.update() function expects two arguments (data and its key) and I have provided two arguments but it complains of having provided three arguments.

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
  • Are you reading the correct documentation: https://docs.python.org/2/library/collections.html#collections.Counter.update ? Plus don't assign the update call back to the same variable, `update()` returns `None`. – Ashwini Chaudhary Sep 26 '15 at 23:33

1 Answers1

0

Since Counter is a class, the first argument that all its methods take is an instance of Counter. The third argument that the interpreter is picking up is Set1, because Set1.update(InputString1[i], arg1) is equivalent to Counter.update(Set1, InputString1[i], arg1).

So you really should only be passing in one argument, an iterable or a mapping, when you call Set1.update. Try this, put the data and its key into a dictionary and pass it through as one argument.

arg1 = InputString1.count(InputString1[i])
Set1 = Set1.update({InputString1[i]: arg1})