Re: del and sets proposal

2008-10-16 Thread Henk . van . Asselt
"Life was like a box of chocolates. You never know what you're gonna get." Regardless of how it is implemented, mathematically a set is a collection of items. The order does not matter, an item is part of a set, or is not part of a set. Period. Henk -- http://mail.python.org/mailman/listinfo/py

Re: del and sets proposal

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote: > On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote: > >> In message <[EMAIL PROTECTED]>, Steven D'Aprano >> wrote: >> >>> Would it really be "confusing" if sets used the same interface as dicts >>> use? I don't think so. What el

Re: del and sets proposal

2008-10-05 Thread Aaron "Castironpi" Brady
Bruno Desthuilliers wrote: Steven D'Aprano a écrit : On Sat, 04 Oct 2008 18:36:28 +0200, Bruno Desthuilliers wrote: Lists are the odd one out, because del alist[x] is used to remove the element at position x, rather than removing an element x. Nope. It's perfectly consistent with dicts, wher

Re: del and sets proposal

2008-10-05 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote: In message <[EMAIL PROTECTED]>, Steven D'Aprano 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

Re: del and sets proposal

2008-10-05 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : On Sat, 04 Oct 2008 18:36:28 +0200, Bruno Desthuilliers wrote: Yes I know that sets have a remove method (like lists), but since dictionaries don't have a remove method, shouldn't sets behave like more like dictionaries and less like lists? IMHO del for sets is quite

Re: del and sets proposal

2008-10-05 Thread Steven D'Aprano
On Sun, 05 Oct 2008 22:11:38 +1300, Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Steven D'Aprano > 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"? >

Re: del and sets proposal

2008-10-05 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano 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"? Yes, but "x" in what sense? In dicts it's a key, in sets, shouldn't it also

Re: del and sets proposal

2008-10-04 Thread Steven D'Aprano
On Sat, 04 Oct 2008 18:36:28 +0200, Bruno Desthuilliers wrote: >> Yes I know that sets have a remove method (like lists), but since >> dictionaries don't have a remove method, shouldn't sets behave like >> more like dictionaries and less like lists? IMHO del for sets is quite >> intuitive. > > F

Re: del and sets proposal

2008-10-04 Thread Bruno Desthuilliers
Larry Bates a écrit : You can do the following: a = [1,2,3,4,5] del a[0] and a = {1:'1', 2: '2', 3: '3', 4:'4', 5:'5'} del a[1] why doesn't it work the same for sets (particularly since sets are based on a dictionary)? a = set([1,2,3,4,5]) del a[1] > Yes I know that sets have a remove met

Re: del and sets proposal

2008-10-03 Thread Marc 'BlackJack' Rintsch
On Fri, 03 Oct 2008 02:09:09 -0700, Carl Banks wrote: > On Oct 2, 8:02 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> Then add subscription access too.  By aliasing `__getitem__()` to >> `__contains__()`.  And `__setitem__()` could be implemented to add or >> remove objects by assignin

Re: del and sets proposal

2008-10-03 Thread bearophileHUGS
Steven D'Aprano: > Personally, I'd rather see dictionaries grow methods like > symmetric_difference, union, etc. than worry about whether you use del or > remove to remove elements from a set. I have functions for all those operations, so I think they can be useful, but in practice I don't use the

Re: del and sets proposal

2008-10-03 Thread Steven D'Aprano
On Fri, 03 Oct 2008 02:18:53 -0700, Carl Banks wrote: > On Oct 2, 11:27 pm, Larry Bates <[EMAIL PROTECTED]> wrote: >> I didn't mean to imply that del a[1] would delete the first thing in >> the set, but rather the item with a value of 1.  Just as when we use it >> on a dictionary: >> >> del a[1] >

Re: del and sets proposal

2008-10-03 Thread Carl Banks
On Oct 2, 11:27 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > I didn't mean to imply that del a[1] would delete the first thing in the set, > but rather the item with a value of 1.  Just as when we use it on a > dictionary: > > del a[1] > > doesn't mean delete the first dictionary entry but rather

Re: del and sets proposal

2008-10-03 Thread Carl Banks
On Oct 2, 8:02 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Thu, 02 Oct 2008 15:39:55 -0700, Chris Rebert wrote: > > On Thu, Oct 2, 2008 at 3:20 PM, Larry Bates <[EMAIL PROTECTED]> > > wrote: > >> a = set([1,2,3,4,5]) > >> del a[1] > > > Sets don't support subscripting, so if you ca

Re: del and sets proposal

2008-10-03 Thread Steven D'Aprano
On Thu, 02 Oct 2008 22:27:04 -0500, Larry Bates wrote: > Maybe dictionaries should have had a .remove method then things would be > more consistent? But why should sets be consistent with dictionaries? There are a few similarities, but also differences. Personally, I'd rather see dictionaries g

Re: del and sets proposal

2008-10-03 Thread George Sakkis
On Oct 2, 6:20 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > You can do the following: > > a = [1,2,3,4,5] > del a[0] > > and > > a = {1:'1', 2: '2', 3: '3', 4:'4', 5:'5'} > del a[1] > > why doesn't it work the same for sets (particularly since sets are based on a > dictionary)? > > a = set([1,2,3,

Re: del and sets proposal

2008-10-02 Thread Larry Bates
Chris Hebert wrote: On Thu, Oct 2, 2008 at 3:20 PM, Larry Bates <[EMAIL PROTECTED]> wrote: You can do the following: a = [1,2,3,4,5] del a[0] and a = {1:'1', 2: '2', 3: '3', 4:'4', 5:'5'} del a[1] why doesn't it work the same for sets (particularly since sets are based on a dictionary)? a =

Re: del and sets proposal

2008-10-02 Thread Marc 'BlackJack' Rintsch
On Thu, 02 Oct 2008 15:39:55 -0700, Chris Rebert wrote: > On Thu, Oct 2, 2008 at 3:20 PM, Larry Bates <[EMAIL PROTECTED]> > wrote: >> a = set([1,2,3,4,5]) >> del a[1] > > Sets don't support subscripting, so if you can't go 'a_set[something]', > why would you expect to be able to be able to 'del'

Re: del and sets proposal

2008-10-02 Thread bearophileHUGS
Chris Rebert: > No, sets are a datatype unto themselves. They are based on > dictionaries internally (at least in CPython), but that's an > implemention detail to be hidden, not emphasized. Later Hettinger has simplified their code, making them use less memory (and be a little faster too, I think)

Re: del and sets proposal

2008-10-02 Thread Marc 'BlackJack' Rintsch
On Thu, 02 Oct 2008 16:48:42 -0700, Jon Clements wrote: > It's also worth noting that removing an object from a container > (.remove) is different than proposing the object goes to GC (del...) ``del`` doesn't propose that the object goes to GC, at least not more then a `remove()` method does. J

Re: del and sets proposal

2008-10-02 Thread Jon Clements
On Oct 2, 11:20 pm, Larry Bates <[EMAIL PROTECTED]> wrote: > You can do the following: > > a = [1,2,3,4,5] > del a[0] > > and > > a = {1:'1', 2: '2', 3: '3', 4:'4', 5:'5'} > del a[1] > > why doesn't it work the same for sets (particularly since sets are based on a > dictionary)? > > a = set([1,2,3,

Re: del and sets proposal

2008-10-02 Thread Chris Rebert
On Thu, Oct 2, 2008 at 3:20 PM, Larry Bates <[EMAIL PROTECTED]> wrote: > You can do the following: > > a = [1,2,3,4,5] > del a[0] > > and > > a = {1:'1', 2: '2', 3: '3', 4:'4', 5:'5'} > del a[1] > > why doesn't it work the same for sets (particularly since sets are based on > a dictionary)? > > a =

del and sets proposal

2008-10-02 Thread Larry Bates
You can do the following: a = [1,2,3,4,5] del a[0] and a = {1:'1', 2: '2', 3: '3', 4:'4', 5:'5'} del a[1] why doesn't it work the same for sets (particularly since sets are based on a dictionary)? a = set([1,2,3,4,5]) del a[1] Yes I know that sets have a remove method (like lists), but sin