$ ./guess_the_languageProblem Solving — fill the blank
Problem Solving — fill the blank · medium · #122

Fill the blank

# returns elements of a that are also in b
def common(a, b):
    b_set = set(b)
    return [x for x in a ____ x in b_set]
# common([1,2,3],[2,3,4]) -> [2,3]

Answer: if (also accepted: if, if())

The if clause filters the comprehension to matching elements.
Play Problem Solving ▸