Created
September 9, 2019 10:19
-
-
Save notpushkin/1ebd2cc6989a68bd93f09831bb7172fe to your computer and use it in GitHub Desktop.
This file contains 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
Python 3.7.3 (default, Apr 3 2019, 05:39:12) | |
Type 'copyright', 'credits' or 'license' for more information | |
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help. | |
In [1]: dick = {'test1': {1,2,3,4,5,}, 'test2': {6,5,2,4,9,}, 'test3': {1, 4, 6, 9}} | |
In [2]: set.intersection? | |
Docstring: | |
Return the intersection of two sets as a new set. | |
(i.e. all elements that are in both sets.) | |
Type: method_descriptor | |
In [3]: from functools import reduce | |
In [4]: reduce? | |
Docstring: | |
reduce(function, sequence[, initial]) -> value | |
Apply a function of two arguments cumulatively to the items of a sequence, | |
from left to right, so as to reduce the sequence to a single value. | |
For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates | |
((((1+2)+3)+4)+5). If initial is present, it is placed before the items | |
of the sequence in the calculation, and serves as a default when the | |
sequence is empty. | |
Type: builtin_function_or_method | |
In [5]: reduce(set.intersection, dick.values()) | |
Out[5]: {4} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment