[Python-bugs-list] Iterator doesn't re-evaluate with a dynamically resizing list (PR#178)

seanj@speakeasy.org seanj@speakeasy.org
Tue, 11 Jan 2000 21:34:53 -0500 (EST)


Full_Name: Sean Jensen-Grey
Version: 1.5.2
OS: W2k 
Submission from: tide87.microsoft.com (131.107.3.87)


l_sync = [ '# comment', '#this is a comment', '#define foo bar' ]

print l_sync

print

for x in l_sync:
	print x

print

for x in l_sync:
	if x[0] == '#':
		print x
		if x[0:2] != '#d':
			l_sync.remove(x)
			
print

print l_sync

# the desired output should be
#define foo bar
# what is happening **I think** is that
# iterator i is set to 0
# l_sync[0] is deleted, array shifts to the left by one
# iterator i is incremented by 1
# l_sync[1] now referes to #define, skipping over
#this is a comment
# the iterator merrily marches along as the array is dynamically resized
# if you change the 
#l_sync = [ '# comment', '#this is a comment', '#define foo bar' ]
#l_sync = [ '# comment', 'foo','#this is a comment', '#define foo bar' ]
# you will see what I mean...





# is this expected behavior?