How to find the element that appears once in a list where other elements appear in pairs with Python

1 Answer

0 votes
def findElementThatAppearsOnce(lst): 
    size = len(lst)
    element = lst[0] 
      
    for i in range(1, size): 
        element = element ^ lst[i] 
      
    return element 
  

lst = [7, 2, 2, 4, 5, 3, 4, 5, 7] 

print(findElementThatAppearsOnce(lst))



'''
run:

3

'''

 



answered Dec 3, 2021 by avibootz
...