[issue41454] while loop bug on list

2020-08-01 Thread Dexter Ramos


New submission from Dexter Ramos :

The output should have no duplicates but it has. When I added another "5" on 
the list it goes okay and is still okay if I add more. But when there is only 
two 5's it won't do its job.

--
components: Windows
files: app.py
messages: 374661
nosy: Dexter Ramos, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: while loop bug on list
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file49356/app.py

___
Python tracker 
<https://bugs.python.org/issue41454>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41454] while loop bug on list

2020-08-01 Thread Dexter Ramos


Dexter Ramos  added the comment:

Thank you Mr. Erick Smith. Now I know. I also tried to find the hard way like 
this:

finding nemo-
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4] --->index
[4, 1, 2, 5, 7, 4, 2, 8, 9, 5, 3, 2, 4, 6] --->original list
 / --->started at index 0 with value of 
4
[1, 2, 5, 7, 2, 8, 9, 5, 3, 2, 6, 4] --->1st iteration, all 4's are removed 
then appended so the index adjusted
/--->next at index 1 with a value of 2 
(whereas value 1 was skipped which had index 1 originally; this is not seen on 
the output because it has no duplicate)
[1, 5, 7, 8, 9, 5, 3, 6, 4, 2] --->3rd iteration
   / --->next at index 2 with value of 7; value 
5 was skipped which had the index 2 originally; cause found!
[1, 5, 8, 9, 5, 3, 6, 4, 2, 7] --->4th ...
...
---nemo found---
Credits to you.

Here is the new working code:
---code
bunchofnumbers = [4, 1, 2, 5, 7, 4, 2, 8, 9, 5, 3, 2, 4, 6]
for eachnumber in bunchofnumbers.copy():
while eachnumber in bunchofnumbers:
bunchofnumbers.remove(eachnumber)
bunchofnumbers.append(eachnumber)
bunchofnumbers.sort()
---end of code-
OUTPUT:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
print(bunchofnumbers)

--

___
Python tracker 
<https://bugs.python.org/issue41454>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com