[Python-bugs-list] [ python-Bugs-643115 ] Creating sets from dictionaries

noreply@sourceforge.net noreply@sourceforge.net
Mon, 25 Nov 2002 12:45:19 -0800


Bugs item #643115, was opened at 2002-11-24 10:54
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=643115&group_id=5470

Category: Python Library
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Martin v. Löwis (loewis)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Creating sets from dictionaries

Initial Comment:
When creating a set from a dictionary, the dictionary
values must not be copied. The following expression
gives, False, but should give True, since both sets
contain the same elements.

>>> from sets import Set
>>> Set({10:10}) == Set([10])
False


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-25 15:45

Message:
Logged In: YES 
user_id=80475

Committed as sets.py  1.36 and test_sets.py 1.18.
Marking as fixed and closing.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-25 15:11

Message:
Logged In: YES 
user_id=6380

I'm for Sets2.diff. The values should never ever be allowed
to be anything else but True; if we can't trust that, we
can't trust any part of the setes module.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-25 03:01

Message:
Logged In: YES 
user_id=80475

Guido, do you have a preference?

BTW, the reasons for my preferring to revise the equality 
tests are:
1.  It's much easier to verify that a revised equality test 
compares only keys than it is to permanently preclude all 
possible ways a foreign value could sneak in.
2.  I would rather slow down an equality test than lose the 
speed of converting a dict to a set (which can occur either 
externalor internal to the module).

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-11-25 02:47

Message:
Logged In: YES 
user_id=21627

I'd be fine with either approach.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-24 23:02

Message:
Logged In: YES 
user_id=80475

There are two ways to go with this one.  Either follow the 
OP suggestion and force all values to be True, or revise the 
equality tests to only compare keys.

I like the second approach but am posting patches for 
both.  If one or the other is approved, will add the failure 
to the test_suite.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=643115&group_id=5470