[Python-ideas] Dictionary views are not entirely 'set like'

Rob Cliffe rob.cliffe at btinternet.com
Wed Apr 6 09:03:04 EDT 2016


Something has changed then, because in Python 2.7.10 I get
     ##1,3     TypeError
     ##9,10   True
I can't see anything wrong with the actual behaviour in any of the examples.
Rob Cliffe

On 06/04/2016 10:38, Joshua Morton wrote:
> Let's start with a quick quiz: what is the result of each of the 
> following (on Python3.5.x)?
>
>     {}.keys() | set()  # 1
>     set() | []  # 2
>     {}.keys() | []  # 3
>     set().union(set())  # 4
>     set().union([])  # 5
>     {}.keys().union(set())  # 6
>
> If your answer was set([]), TypeError, set([]), set([]), set([]), 
> AttributeError, then you were correct. That, to me, is incredibly 
> unintuitive.
>
> Next up:
>
>     {}.keys() == {}.keys()  # 7
>     {}.items() == {}.items()  # 8
>     {}.values() == {}.values()  # 9
>     d = {}; d.values() == d.values()  # 10
>
> True, True, False, False.
>
> Numbers 1, 2, 4, 5 are expected behavior. 3 and 6 are not, and 7-10 is 
> up for debate.[1]
>



More information about the Python-ideas mailing list