Re: Can't get items out of a set?

2008-03-09 Thread Raymond Hettinger
The intern() builtin uses this approach:    interned = {}    def intern(s):         if s in interned:             return interned[s]         interned[s] = s         return s If you've seen it before, and have the old one, return the old one. Do I have this straight? Right. --

Re: Can't get items out of a set?

2008-03-08 Thread Alan Isaac
Cruxic wrote: people = set( [Person(1, 'Joe'), Person(2, 'Sue')] ) ... p = people.get_equivalent(2) #method doesn't exist as far as I know print p.name #prints Sue def get_equivalent(test, container): for p in container: if p == test: return p hth, Alan Isaac

Re: Can't get items out of a set?

2008-03-08 Thread Cruxic
On Mar 7, 11:20 am, Raymond Hettinger [EMAIL PROTECTED] wrote: [Cruxic] Is it possible to get an object out of a set() given another object that has the same hash code and equality (__hash__() and __eq__() return the same)? Yes, but it requires an indirect

Re: Can't get items out of a set?

2008-03-08 Thread Cruxic
On Mar 8, 7:32 am, Alan Isaac [EMAIL PROTECTED] wrote: Cruxic wrote: people = set( [Person(1, 'Joe'), Person(2, 'Sue')] ) ... p = people.get_equivalent(2) #method doesn't exist as far as I know print p.name #prints Sue def get_equivalent(test, container): for p in container:

Re: Can't get items out of a set?

2008-03-08 Thread Raymond Hettinger
Is it possible to get an object out of a set() given another object that has the same hash code and equality (__hash__() and __eq__() return the same)? Yes, but it requires an indirect approach.http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/499299 Raymond That's a

Re: Can't get items out of a set?

2008-03-08 Thread castironpi
something something equivalence class. The intern() builtin uses this approach:    interned = {}    def intern(s):         if s in interned:             return interned[s]         interned[s] = s         return s If you've seen it before, and have the old one, return the old one. Do I

Can't get items out of a set?

2008-03-07 Thread Cruxic
Hello, all. Is it possible to get an object out of a set() given another object that has the same hash code and equality (__hash__() and __eq__() return the same)? You can't do this with Java Sets either and I've needed it on multiple occasions. Doesn't it seem like it would be useful?

Re: Can't get items out of a set?

2008-03-07 Thread Raymond Hettinger
[Cruxic] Is it possible to get an object out of a set() given another object that has the same hash code and equality (__hash__() and __eq__() return the same)? Yes, but it requires an indirect approach. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/499299 Raymond --