Bite 323. Iterables intersection
Login and get codingIn this bite we are going to work on coding a function
intersection()that searches the common elements across its input. More specifically:- Input to the function will be one, two or more objects which can be iterated on (e.g.,
list,tuple,str)- The function's output is a
setcontaining the intersection across input iterables, or an emptysetif no common elements are foundNotes:
- Filter out inputs which are
Noneor empty- If after the filter you end up with just one iterable, the output is a set with the unique elements in that iterable (see last example below)
Here is how it works in the Python interpreter's Read Execute Print Loop (REPL):
>>> from intersection import intersection
>>> intersection({1,2,3}, {2,3,4}, {3,4})
{3}
>>> intersection([1,2,3,"1"], {1,-1}, {})
{1}
>>> intersection(None, "this is a string")
{' ', 'a', 'g', 'h', 'i', 'n', 'r', 's', 't'}Note: the template provides a hint to use a standard library module that can help you, but it is not mandatory for solving this bite (i.e., there are at least two ways to code
intersection())
115 out of 117 users completed this Bite.
Will you be the 116th person to crack this Bite?
Resolution time: ~57 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 4.25 on a 1-10 difficulty scale.
» Up for a challenge? 💪