Solution (source code)

= Solution

Using the <indicator random variable>, sum over the values of the <discrete random variable> $X$:
$$
\mathbb E[X\mathbf1_B]=\sum_x x\,\mathbb P(\{X=x\}\cap B)=\mathbb P(B)\sum_x x\,\mathbb P(X=x\mid B).
$$
Dividing by the positive <probability> $\mathbb P(B)$ proves \b[$\mathbb E[X\mid B]=\mathbb E[X\mathbf1_B]/\mathbb P(B)$]. On $B^c$ the product vanishes, so no additional contribution is omitted.