How to stop the loop when the same values appear in the list in Python? : [enter image description here][1]


  [1]: https://i.stack.imgur.com/RmOKX.png

Above my task. I have to stop the loop  when the same items appear in the list then sum them.
  

      def squareA(a,b):
        res = []
        z = 0
    
        while z!= 3:
            
           res.insert(0,(a + z)**2)
           res.insert(0,(b - z)**2)
           z += 1
               
            
    
    
    
        print(res)
        res = list(dict.fromkeys(res))
        print(res)
        res = sum(res)
    
        return res
    
    a = 5
    b = 6
    print(squareA(a,b))

