Reputation: 584
I have written the below code for getting the only unique element in a given integer array.
def lonelyinteger(a):
for x in a:
answer = a.count(x)
if(a.count(x) < 2)
answer=x
return answer
if __name__ == '__main__':
a = input()
b = map(int, raw_input().strip().split(" "))
print lonelyinteger(b)
Error
File "solution.py", line 5 if(a.count(x) < 2) ^ SyntaxError: invalid syntax
Exit Status 255
Please tell me where did I miss
Upvotes: 1
Views: 12801
Reputation: 1100
Correct code below this (your code modified):
def lonelyinteger(a):
# added a : that was missing in the for
# loop (syntax error)
for x in a:
answer = a.count(x)
if(a.count(x) < 2):
answer=x
return answer
if __name__ == '__main__':
a = input()
b = map(int, raw_input().strip().split(" "))
print lonelyinteger(b)
Upvotes: -1