Here's the exercise:
I've already constructed $g(x)$ as suggested in the exercise, the problem is my "proof" that $g(x)$ is continuous.
So, let $p\in{X}$ and $\{p_n\} \to{p}$. Now define a new sequence $\{q_n\}$ such that
$$q_n=\begin{cases}p_n, & \text{if $\ p_n\in{E}$}\\x, & \text{such that $d_X(p_n, x) \lt 1/n$ and $x\in{E}$}\end{cases}$$
Now, it's clear that $$\{d_X(p_n, q_n)\} \to{0}$$ and therefore $$\{q_n\} \to{p}.$$
Since $\{q_n\} \in{E}$ we also have that
$$\{f(q_n)\} \to f(p)$$
from which it (should) follow that
$$\{f(p_n)\} \to f(p).$$
Obviously my full proof is more elaborate, but this is basically the gist of it. The problem is that at no point am I assuming that $f(X)$ is complete and it should therefore for hold for any metric space. But I've seen examples of metric spaces where it doesn't hold so my proof must be faulty.
Edit:
So I realized that the second to last statement doesn't imply the last statement. I found a solution online here:
However, I still don't why see $f(X)$ needs to be complete.
