I keep solving coding challenges and am able to do them quite simply. But the problem arises once I try to compact the code into a style that uses ternary operators. In this problem, I am trying to find the integer that occurs an odd amount of times in an array. I do this in the normal, good practice form and everything is fine.
def find_it(seq):
for x in seq:
if seq.count(x) % 2 == 1:
return x
This works but when I try to turn it into something like this:
def find_it(seq):
for x in seq:
return x if seq.count(x) % 2 == 1
It gives this error almost every time I try ternary operators:
File "<string>", line 10
return x if seq.count(x) % 2 == 1
^
SyntaxError: invalid syntax
What is the issue? Why does it always say invalid syntax?