[Python-Dev] Dict constructor

Raymond Hettinger python@rcn.com
Wed, 26 Jun 2002 03:36:21 -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


Raymond Hettinger
'regnitteh dnomyar'[::-1]