i want to get know how many pair of numbers are present in the list
ar=[10 ,20 ,20 ,10 ,10 ,30 ,50 ,10 ,20]
this is the list
and i want to get the output 3. because there are 2 pair of 10 and one pair of 20
and this is my code
for i in ar:
print(i)
if ar.count(i)%2:
ar.remove(i)
print('removing ..' ,i)
print('numbers of pairs is : ',len(ar)//2)
print('after removing the odds ',ar)
output
10
20
removing .. 20
10
10
30
removing .. 30
10
20
numbers of pairs is : 3
after removing the odds [10, 20, 10, 10, 50, 10, 20]
why this code is not removing the 50 from the list ?
i'm using jupyter notebook and i run this code onces again and the output is:
10
20
10
10
50
removing .. 50
20
numbers of pairs is : 3
after removing the odds [10, 20, 10, 10, 10, 20]
the for loop is not reading the 50 from the array at the first run. that's why this code is not working, and my question is , why ,for loop is not reading this number ?