Is there a Python dict without values?

后端 未结 3 1420
-上瘾入骨i
-上瘾入骨i 2021-01-07 19:02

Instead of this:

a = {\"foo\": None, \"bar\": None}

Is there a way to write this?

b = {\"foo\", \"bar\"}

3条回答
  •  时光说笑
    2021-01-07 19:34

    In order to "key" into a set in constant time use in:

    >>> s = set(['foo', 'bar', 'baz'])
    >>> 'foo' in s
    True
    >>> 'fork' in s
    False
    

提交回复
热议问题