View Single Post
Old Jun 8th, 2006, 9:46 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,869
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
I think the problem may be that it's iterating through a list that you're changing.

Create a temporary copy of the list before, then copy back after like so:

# does not work
for i in range(len(num)): # i is the index of each digit
	letters = numdict[int(num[i])]
        templist = namelist[:] # create a direct copy of the list rather then referencing it
	for name in namelist:
		if name[i] not in letters:
			templist.remove(name)
        namelist = templist[:]

If that doesn't work, please post a runnable version of the code to demonstrate the problem. Right now I don't know how to piece your snippets together.
Sane is offline   Reply With Quote