Is there a Python dict without values?

Actually, in Python 2.7 and 3.2+, this really does work:

>>> b = {"foo", "bar"}
>>> b
set(['foo', 'bar'])

You can’t use [] access on a set (“key into”), but you can test for inclusion:

>>> 'x' in b
False
>>> 'foo' in b
True

Sets are as close to value-less dictionaries as it gets. They have average-case constant-time access, require hashable objects (i.e. no storing lists or dicts in sets), and even support their own comprehension syntax:

{x**2 for x in xrange(100)}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)