[Python-Dev] Dict constructor

Guido van Rossum guido@python.org
Fri, 12 Jul 2002 13:17:57 -0400


> Second wild idea of the day:
> 
> The dict constructor currently accepts sequences where each element has
> length 2, interpreted as a key-value pair.
> 
> Let's have it also accept sequences with elements of length 1, interpreted
> as a key:None pair.
> 
> The benefit is that it provides a way to rapidly construct sets:
> 
> lowercase = dict('abcdefghijklmnopqrstuvwxyz')
> if char in lowercase: ...
> 
> dict([key1, key2, key3, key1]).keys()  # eliminate duplicate keys

Rejecting (even in the modified form you showed after prompring from
Tim).  I think the dict() constructor is already overloaded to the
brim.  Let's do a set module instead.  There's only one hurdle to take
for a set module, and that's the issue with using mutable sets as
keys.  Let's just pick one solution and implement it (my favorite
being that sets simply cannot be used as keys, since it's the
simplest, and matches dicts and lists).

--Guido van Rossum (home page: http://www.python.org/~guido/)