Set and {} comparison confusion

Alex Martelli aleaxit at yahoo.com
Thu Sep 9 06:37:01 EDT 2004


Heiko Wundram <heikowu at ceosg.de> wrote:

> Am Donnerstag, 9. September 2004 10:18 schrieb Alex Martelli:
> > def same_as_sets(onelist, another):
> >     for item in onelist:
> >         if item in another: return False
> >     for item in another:
> >         if item in onelist: return False
> >     return True
> 
> Minor correction, shouldn't this be:
> 
> for item in onelist:
>   if item not in another: return False
> ...
> 
> Notice the nice little word not, which makes all the difference... ;)

Heh, yes, of course -- we're checking set equality, not complete
disjunction (which would only need half the amount of work!-)


Alex



More information about the Python-list mailing list