A "for" with "list" question.

Mauro mauro at mr-potatohead.com
Sat Aug 31 23:30:51 CEST 2002


Hy to all,

I've got 2 lists and I want to print print only the common, itens in
both lists and the not common after.

Exemple:

a = [0,1,2]
b = [1,2,3]

1° Print only -> 1 and 2
Because the 1 and 2 are the only than appears in both lists.

2° Print only -> 0 and 3
This are the itens than are only in their lists.


I tried to use like this:

for a in b:
    print b[a]

But it appears:

2
3
Traceback (most recent call last):
  File "<pyshell#106>", line 2, in ?
    print b[a]
IndexError: list index out of range

Thanks if some one help-me

Mauro
mauro at mr-potatohead.com



More information about the Python-list mailing list