How to access an element of a set using an equivalent object?
If I have an object that compares equal to an element of a Python set, but is not the same object, is there a reasonable way to get a reference to the object in the set? The use case would be using the set to identify and share duplicated data. Example (Python 2.7): >>> a = "This is a string" >>> b = "This is a string" >>> a is b False >>> a == b True >>> s = set((a,)) >>> b in s True How to get a reference to a using b and s? I can think of one way, but I'm not sure if it is not implementation-dependent whether you get a or b. EDIT: This does not work when s has more than one element; interse
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.