del and sets proposal

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Oct 3 09:59:20 EDT 2008


On Fri, 03 Oct 2008 02:09:09 -0700, Carl Banks wrote:

> On Oct 2, 8:02 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
>> Then add subscription access too.  By aliasing `__getitem__()` to
>> `__contains__()`.  And `__setitem__()` could be implemented to add or
>> remove objects by assigning truth values.  So hypothetically:
>>
>> >>> a = set([1, 2, 3])
>> >>> a[1]
>> True
>> >>> a[4]
>> False
>> >>> a[2] = False
>> >>> a
>> set([1, 3])
>> >>> a[4] = True
>> >>> a
>> set([1, 3, 4])
>> >>> del a[1]
>> >>> a
>>
>> set([3, 4])
>>
>> I wouldn't want that addition to `set`\s but at least it can be
>> implemented without introducing inconsistencies.
> 
> 
> If set behaved that way then "del a[1]" wouldn't behave like del
> anymore.  Normally, "del whatever" means that you can no longer use
> "whatever"; in this proposal you can.

Then there should be no ``del`` for `collections.defaultdict`:

In [169]: from collections import defaultdict

In [170]: d = defaultdict(int)

In [171]: d[42]
Out[171]: 0

In [172]: del d[42]

In [173]: d[42]
Out[173]: 0

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list