Re: del and sets proposal
On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote:
The only sense possible.
If I wrote aset.remove(x) would you ask "what's x, a key or a value?" No
of course you wouldn't, because the question is nonsense for sets. The
same goes for "x in aset", "aset.add(x )" and any other set method that
takes an element as an argument. Why are you singling out del for this
pretend confusion?
That question isn't even meaningful. Sets have elements. The semantics of
set elements is closer to dictionary keys than to dictionary values:
x in adict # is key x in dictionary?
x in aset # is element x in set?
and an early implementation of Python sets used dictionaries, where the
elements where stored as keys, not values. It makes no sense to treat set
elements as if they were analogous to dict values.
Why on earth should "del aset[x]" imply that sets are ordered? Dicts
aren't ordered. You don't find people going "wibble wibble wibble, I
don't understand del adict[x] because dicts aren't ordered, what could it
mean???"
--
Steven
On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote:
In message <00f80c6a$0$206 33$c3e8da3@news .astraweb.com>, Steven D'Aprano
wrote:
>
>
Yes, but "x" in what sense?
wrote:
>
>Would it really be "confusing" if sets used the same interface as dicts
>use? I don't think so. What else could "del aset[x]" mean other than
>"delete element x"?
>use? I don't think so. What else could "del aset[x]" mean other than
>"delete element x"?
Yes, but "x" in what sense?
If I wrote aset.remove(x) would you ask "what's x, a key or a value?" No
of course you wouldn't, because the question is nonsense for sets. The
same goes for "x in aset", "aset.add(x )" and any other set method that
takes an element as an argument. Why are you singling out del for this
pretend confusion?
In dicts it's a key, in sets, shouldn't it
also be a key and not a value?
also be a key and not a value?
set elements is closer to dictionary keys than to dictionary values:
x in adict # is key x in dictionary?
x in aset # is element x in set?
and an early implementation of Python sets used dictionaries, where the
elements where stored as keys, not values. It makes no sense to treat set
elements as if they were analogous to dict values.
Sets have no keys, only values. One might suggest assignment of keys, Ã
la array indexes, but that means assigning an ordering to the values,
whereas sets are explicitly unordered.
la array indexes, but that means assigning an ordering to the values,
whereas sets are explicitly unordered.
aren't ordered. You don't find people going "wibble wibble wibble, I
don't understand del adict[x] because dicts aren't ordered, what could it
mean???"
--
Steven
Comment