Hello I have a loop which goes counts different records in my MySQL database and then saves the numbers to a list. Here is the list:
[1L, 2L, 2L, 5L, 4L, 1L, 1L, 1L, 3L, 1L, 1L, 2L, 2L, 3L, 3L, 1L, 2L, 4L, 2L, 1L, 3L, 1L, 2L, 4L, 1L, 2L, 1L, 1L, 3L, 1L, 3L, 1L, 5L, 2L, 1L, 1L, 5L, 1L, 1L, 1L, 4L, 2L, 1L, 3L, 2L, 1L, 2L, 2L, 2L, 3L, 1L, 1L, 3L, 2L, 2L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 3L, 3L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L]
now I go thru this list and I want to leave only single numbers (means 1L, 2L etc) I’m using this loop:
for number in legend:
print number # to check what number it does currently
counter = legend.count(number)
while counter > 1:
legend.remove(number)
counter -= 1
then I see that it checks 1,2,3,4,3,2,1 …why is that? why this loop wont check number 5? at the end the list looks like this:
[5L, 5L, 5L, 4L, 3L, 2L, 1L]
that means it works but why it doesn’t go for number 5?
thx in advance
Just put it in a
set.This will automatically filter out all duplicates. Maybe you can even skip the list, and put it in a
setin the first place.