A "for" with "list" question.

Gerhard Häring gerhard.haering at gmx.de
Sat Aug 31 17:44:05 EDT 2002


* Mauro <mauro at mr-potatohead.com> [2002-08-31 14:30 -0700]:
> 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.

These are set operations. You could download a set implementation for
Python or program the necessary functions yourself.

> I tried to use like this:
> 
> for a in b:
>     print b[a]

Do you actually know what b[a] does? Maybe you should check your
assumption on what it does again ;-)

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list