Created
January 21, 2018 17:57
-
-
Save inesusvet/200b27c95ad6e6dee19ec339439b14e9 to your computer and use it in GitHub Desktop.
PoC for comparison of dict.items() as check that sub-dict is contained
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [39]: a = {} | |
In [40]: for i in xrange(4): | |
...: key = ''.join(random.sample(string.ascii_lowercase, 10)) | |
...: a[key] = key | |
...: | |
In [41]: a | |
Out[41]: | |
{'beuvqlcnyp': 'beuvqlcnyp', | |
'ecnwgifjpu': 'ecnwgifjpu', | |
'lhupednsvi': 'lhupednsvi', | |
'mzogtjsqfn': 'mzogtjsqfn'} | |
In [42]: ai = a.items() | |
In [43]: b = a.copy() | |
In [44]: for i in xrange(100): | |
...: key = ''.join(random.sample(string.ascii_lowercase, 10)) | |
...: b[key] = key | |
...: if ai > b.items(): | |
...: print 'Whoops', len(b) | |
...: break | |
...: | |
Whoops 22 | |
In [45]: a.items() <= b.items() | |
Out[45]: False | |
In [46]: set(a) <= set(b) | |
Out[46]: True | |
In [47]: set(a.items()) <= set(b.items()) | |
Out[47]: True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment