[Tutor] Question about equality of sets
spir
denis.spir at gmail.com
Sun Apr 6 11:25:16 CEST 2014
On 04/05/2014 07:46 PM, Jim Byrnes wrote:
> Ubuntu 12.04 python 3.3
>
> I was working through an exercise about sets. I needed to find the duplicates in
> a list and put them in a set. I figured the solution had to do with sets not
> supporting duplicates. I finally figured it out but along the way I was
> experimenting in idle and got some results I don't understand.
>
>>>> s = {1,2,3}
>>>> s
> {1, 2, 3}
>>>> s.add(1) == s # <1>
> False
>>>> s.add(1) == s.add(2) # <2>
> True
>>>>
>
> Neither <1> or <2> changes s, so why is <1> False and <2> True ?
The core issue is that set.add()
* is not a computation-function that compute a new set, here like 's' but with a
possible additional item (1 or 2)
* is an action-function that just possibly puts an item in a set
This function returns nothing, in fact None. So you are comparing first None
with s, second none with None.
d
More information about the Tutor
mailing list