Difference in intersection behavior between dict.viewkeys () and tuple between 2.7.10 and 2.7.13

So after reading the changelog between the two versions Python 2.7.10 and Python 2.7.13, nothing came of it, which would explain the following behavior.

Python 2.7.10

Python 2.7.10 (default, Aug  7 2015, 10:34:58) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> d = dict(foo='bar', bar='baz', fee='fum', baz='fee')
>>> keys = ('baz', 'bar')
>>> d.viewkeys() & keys
set([])

      

Python 2.7.13

Python 2.7.13 (default, Dec 17 2016, 23:03:43) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> d = dict(foo='bar', bar='baz', fee='fum', baz='fee')
>>> keys = ('baz', 'bar')
>>> d.viewkeys() & keys
set(['bar', 'baz'])

      

I was wondering if anyone has an explanation for this behavior.

+3


source to share


1 answer


I think this text in What's New in Python 2.7.13 describes the problem:

- Issue # 26478: Fix semantic errors when using binary operators with dictionary representations and tuples.



More on bug 26478 and previous SO question

+1


source







All Articles