Inconsistent behaviour between dict.items and dict.values

前端 未结 4 1883
北海茫月
北海茫月 2021-01-23 00:40

Note: code examples in python3, but the question stands for python2 as well (replacing .keys with .viewkeys, etc)<

4条回答
  •  一生所求
    2021-01-23 01:30

    The reason is that it's not implemented in the dict_values type or because the dict_values class specifically disallows it.

    Since your values are generally a non-unique list of items it's not a great idea to convert it to a set. If you do want that, just manually convert it. My assumption is that it's disallowed since it's generally a bad idea as it can cause data loss.

提交回复
热议问题