Python's “in” set operator

前端 未结 5 1148
刺人心
刺人心 2020-12-25 09:24

I\'m a little confused about the python in operator for sets.

If I have a set s and some instance b, is it true that b i

5条回答
  •  清歌不尽
    2020-12-25 09:52

    Sets behave different than dicts, you need to use set operations like issubset():

    >>> k
    {'ip': '123.123.123.123', 'pw': 'test1234', 'port': 1234, 'debug': True}
    >>> set('ip,port,pw'.split(',')).issubset(set(k.keys()))
    True
    >>> set('ip,port,pw'.split(',')) in set(k.keys())
    False
    

提交回复
热议问题