Continuous Functions and Metric Spaces 
Let $(X, d_x)$ and $(Y, d_y)$ be metric spaces. Let $f: X \rightarrow Y$ be a function.
Show that $f$ is continuous (w.r.t. the metrics $d_x, d_y$) if and only if $f$ inverts closed sets to closed sets.

I know that a continuous function maps compact sets to compact sets. Would the proof for this have something to do with that? Since compact sets are closed and bounded, it makes sense that a continuous function has to map closed sets to closed sets (for the compact sets to compact sets fact to hold).
I'm a bit stuck on the closed sets to closed sets $\implies$ continuous function part. Every point in a closed set is an accumulation point; and, for a function to be continuous, whenever a real sequence $(a_n)$ converges to $p$, then $f(a_n)$ must converge to $f(p)$ as well. How do I make the connection between the RHS and LHS?
Any help would be greatly appreciated. Thank you.
 A: No, it has nothing to do with compactness.
Rather, to show the if and only if statement, first we note that $f$ inverts closed sets to closed sets if and only if $f$ inverts open sets to open sets, since we have the formula that $f^{-1}(Y-G)=X-f^{-1}(G)$.
Now observe that any open set $G$ in metric space can be written as $G=\displaystyle\bigcup_{i}B(x_{i},r_{i})$ for some open balls $B(x_{i},r_{i})$.
And we have the formula that $f^{-1}\left(\displaystyle\bigcup_{i} B(x_{i},r_{i})\right)=f^{-1}(B(x_{i},r_{i}))$.
Finally, for the statement like $d_{X}(y,x)<\delta\rightarrow d_{Y}(f(y),f(x))<\epsilon$ indicates that $B_{X}(x,\delta)\subseteq f^{-1}(B(f(x),\epsilon))$.
A: You don't have to think about compactness. Remember that a function is continuous if and only if the preimage of an open set is always open.
Suppose that for any closed set $V \subset Y$ we have that $f^{-1}(V)$ is closed. Let $U \subset Y$ be open. Then the complement $Y \setminus U$ is closed (by definition). From basic set theory (https://proofwiki.org/wiki/Preimage_of_Set_Difference_under_Mapping),
$$
f^{-1}(Y \setminus U) = f^{-1}(Y) \setminus f^{-1}(U) = X \setminus f^{-1}(U)
$$
Thus $X \setminus f^{-1}(U)$ is closed, so $f^{-1}(U)$ is open. Thus $f$ is continuous.
A: Another definition of continuity of a function is Topological sense is that if $f:X\rightarrow Y$ is a continuous function where $X$ and $Y$ are two Topological spaces then, for any open set $U\subset Y$, $f^{-1}(U)$ is open in X.
Since every metric space is a Topological space so the above holds in metric space too.
Now for any closed set $F\subset Y$ we have $Y\setminus F$ is open in $Y$. By the definition $f^{-1}(Y\setminus F)$ is open in $X$ implies, $f^{-1}(Y)\setminus f^{-1}(F)$ is open in $X$ implies, $X\setminus f^{-1}(F)$ open in $X$ hence, $f^{-1}(F)$ is closed in $X$. Converse holds by similar arguments.
