Help me out with bugs in my list ?

Mindy csshi99 at yahoo.com
Thu Nov 7 23:18:29 EST 2002


Hey, I have two lists like:
binding_list =
["ls","ls","ls","netscape","netscape","lib","lib"]

to_list =
["ls","lib","ls","netscape","ls","lib","lib"]

I want to get non-duplicated pairs of strings from
them like
(binding_list[i],to_list[i]) by eliminating the
duplicated pairs. For the above two lists, I want to
get two new lists:
binding_list = ['ls', 'ls', 'netscape', 'netscape',
'lib']
to_list = ['ls', 'lib', 'netscape', 'ls', 'lib']

My codes are like the following, but I got the result
as:
binding_list = ['ls', 'ls', 'netscape', 'netscape',
'lib','lib']
to_list = ['ls', 'lib', 'netscape', 'ls', 'lib','lib']

With the last two pairs duplicated. I know I was wrong
because at the last loop, index1 = 4, index2 =1, even
though the fifth pair is the same with the fourth
pair, my codes can't detect this. Could anyone help me
to get a correct piece of codes? Thanks so much!

My codes:
----------------
for i in range(1,len(binding_list)):  
    if (i == len(binding_list)): 
	break
index1 = binding_list.index(binding_list[i])
index2 = to_list.index(to_list[i])
if ((index1 >=0)and(index2 >=0)and(index1==index2)):
	del binding_list[i]
	del to_list[i]

print binding_list
print to_list



=====
Cheers
-Mindy

__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2




More information about the Python-list mailing list