[Python-Dev] Set data type
Ka-Ping Yee
ping@lfw.org
Thu, 3 Feb 2000 20:32:28 -0600 (EST)
On Thu, 3 Feb 2000, Ka-Ping Yee wrote:
> On Thu, 3 Feb 2000, Greg Stein wrote:
> >
> > I think the follow is just as readable, if not more so:
> >
> > >>> s = set(1, 5, 7)
> >
> > Where set() is a new builtin, taking an arbitrary number of arguments and
> > returning a new Set type.
Oh, waitasec. On further thought, this produces surprising
behaviour when compared to list() and tuple():
>>> list((1, 2, 3))
[1, 2, 3]
>>> list(1, 2, 3)
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: list() argument must be a sequence
>>> list(3)
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: list() argument must be a sequence
>>> tuple([1, 2, 3])
(1, 2, 3)
>>> tuple(3)
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: tuple() argument must be a sequence
Now look...
>>> set([1, 2, 3])
# {1, 2, 3} or {[1, 2, 3]}?
>>> set(1)
# {1} or TypeError?
I still think set(x, y) -> {x, y} is nice, but it is unfortunate
that set() and list() would work differently. Perhaps if we
think of set() in the same category as slice() it makes more sense.
-- ?!ng