You broke the line where it should not, within set(...)
. I think the way you wanted to be this:
entrada = input()
letras_unicas = set([i for i in set(list(entrada)) if entrada.count(i) %2 != 0])
if len(letras_unicas) > 1:
print(len(letras_unicas)-1)
else:
print(0)
However, this code still does not work completely. Well, he's just looking at the first line of the entrance. If the first line is batata
, it will output 1
. If it is aabb
, it will give 0. If it is abc
, it will give 2. These are the expected results.
See here that running on ideone.
To end the exercise, I think the only thing you will need to do is put a loop to read several lines of the file. Each time the input()
is executed, one line is read, then a while True:
would be enough to read all the lines. Use a try
with a except EOFError
and a break
as a stop condition to exit the loop.
The code would look like this:
while True:
try:
entrada = input()
except EOFError:
break
letras_unicas = set([i for i in set(list(entrada)) if entrada.count(i) %2 != 0])
if len(letras_unicas) > 1:
print(len(letras_unicas)-1)
else:
print(0)
See here that running on ideone.