For the forward implication, consider the composition . For the reverse implication, take Y=A and f to be the identity map.

Show that for a continuous map r, the set is closed.

A nonempty open subset A of X has a finite complement. Define the retraction map to be the identity on A, and let it map the finitely many elements not in A to some random element of A. (You then have to prove that this map is continuous. In other words, if a set has a finite complement, then its inverse image under this map should also have a finite complement.)