compare list

bonono at gmail.com bonono at gmail.com
Tue Nov 15 07:51:05 EST 2005


Simon Brunning wrote:
> On 15/11/05, Ben Bush <pythonnew at gmail.com> wrote:
> > I found I named the following python file as sets.py, which brought the
> > problem (is that right?). i changed it to other name and it works.
> > But the logic output is wrong.
> > from sets import Set as set
> > lisA=[1,2,5,9]
> > lisB=[9,5,0,2]
> > lisC=[9,5,0,1]
> > def two(sequence1, sequence2):
> >    set1, set2 = set(sequence1), set(sequence2)
> >    return len(set1.intersection(set2)) == 2
> >  print two(lisA,lisB)
> > False(should be true!)
>
> It looks to me like A and B have three members in common - 2, 5 and 9.
>
Any chance that while "two" performs correctly for what is intended, it
is not what the OP wants ?

Seems that he only thins the "5,9"/"9,5" are the common case, thus
expect 2 ?




More information about the Python-list mailing list