Login and get codingA dictionary comprehension is like a list comprehension, but it constructs a
dict
instead of alist
. They are convenient to quickly operate on each (key
,value
) pair of adict
. And often in one line of code, maybe two after checking PEP8 ;)We think they are elegant, that's why we want you to know about them!
In this Bite you are given a dict and a set. Write a dictionary comprehension that filters out the items in the
set
and returns the resultingdict
, so if your dict is{1: 'bob', 2: 'julian', 3: 'tim'}
and your set is{2, 3}
, the resulting dict would be{1: 'bob'}
.Check out the tests for more details. Have fun!
1203 out of 1213 users completed this Bite.
Will you be the 1204th person to crack this Bite?
Resolution time: ~26 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 3.14 on a 1-10 difficulty scale.
» You can do it! 😌