Akshay is given a list of n integers. Each number in the list appears exactly twice except one number.help Akshay by identifying the number which appeared once in the list.
def singl_number(L):
  D = {}
  for x in L:
    D[x] = D.get(x, 0) + 1
 Â
  for x in D:
    if D[x] == 1:
      return x
def main():
  L = [1, 2, 2, 3, 1]
  x = singl_number(L)
  print(f'The number {x} appears once in the list {L}')
main()
Comments
Leave a comment