[Python-ideas] Set Syntax

Gerald Britton gerald.britton at gmail.com
Mon Nov 22 17:02:19 CET 2010


Hi -- thought I'd chime in on this one:

> I'd be happy with:
>
> * {:} for empty dict() (as a collection of key-value *pairs*)
> * {.} for empty set() (as a similar collection of *single* elements)
>
> And {} for empty dict() as well -- to keep compatibility (maybe to be
> deprecated later).

Note that dictionaries and sets have clear() methods:

>>> d = {1:2}
>>> d
{1: 2}
>>> d.clear()
>>> d
{}
>>> s = set([1,2])
>>> s
set([1, 2])
>>> s.clear()
>>> s
set([])

Deques have this method as well:

>>> from collections import deque
>>> q = deque([1,2])
>>> q
deque([1, 2])
>>> q.clear()
>>> q
deque([])

If lists had the clear() method, then the basic collection objects
would be in alignment.

-- 
Gerald Britton



More information about the Python-ideas mailing list