object aware of others

Chris Angelico rosuav at gmail.com
Sun Jan 29 00:17:09 EST 2012

On Sun, Jan 29, 2012 at 4:12 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 1/28/2012 11:02 PM, Chris Angelico wrote:
>> If you're looking only at other objects of the same class, the easiest
>> way is to maintain a list every time one is created. Then you just
>> iterate over that list to know about your friends.
> Sets are much better for removal.

True. I've wanted to keep some track of order, so a list is better,
but the original example had nothing to do with order. Set,
definitely. In any case, the technique is the same: maintain a list
explicitly instead of looking through globals (which depends on the
objects in question having global names bound to them).


More information about the Python-list mailing list