New submission from Isaac <isaacloves2...@yahoo.com>:

The simple repro below, shows that if a list of strings has two consecutive 
items that begin with the same letter, an iteration over the list to find and 
remove all strings that start with that letter fails.  The second string that 
starts with the same letter to remove remains in the list.

In the example below, both "bananna" and "blueberry" should be removed from the 
list, but only "bananna" is removed.

I verified this on both 2.7 and 3.2.

-----------------------------------------------------
--- Output ---
--------------
Before: ['apple', 'bananna', 'blueberry', 'coconut']
After:  ['apple', 'blueberry', 'coconut']

-----------------------------------------------------
--- Repro ---
-------------
itemList = ["apple", "bananna", "blueberry", "coconut"]
print("Before: {0}".format(itemList))

for item in itemList:
    if(item.startswith("b")):
        itemList.remove(item)

print("After:  {0}".format(itemList))

----------
files: listRemovalBug.py
messages: 164219
nosy: Eklutna
priority: normal
severity: normal
status: open
title: list.startswith() and list.remove() fails to catch consecutive items in 
a list.
type: behavior
versions: Python 2.7, Python 3.2
Added file: http://bugs.python.org/file26193/listRemovalBug.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15214>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to