Question: > 
> Let $X$ be a connected metric space and $D$ a set. Let $f: X \to D$ such that for every $x \in X$ there is a neighborhood in which $f$ is constant. Show that $f$ is constant.
> 
> 
> 

I'm trying to get the hang of the problem, but this seems somewhat self explanatory? Perhaps I'm not understanding it correctly. If we have that $\forall x \in X:$ $\exists V\_\varepsilon(x)$ such that $f$ is constant then wouldn't it imply that it must be constant all in all? The open sets acts as covers for $X$ and since $X$ is connected they cover whole $X$ right?

Answer: 
*Hint*:

If $D$ has only one element, there is nothing to prove, so assume that $D$ has at least two different elements $a$ and $b$ and suppose for the sake of contradiction that there exist some $x,y\in X$ such that $f(x)=a$ and $f(y)=b$. Define two subsets in $X$:

* Let $U=\{t\in X:f(t)=a\}$.
* Let $V=X\setminus U$.

Are they empty? Are they open? Is their union $X$? Are the disjoint? What does this imply? Be careful with the second question: this is the crucial point of the problem.
**Hint** Pick some arbitrary $a \in X$ and set $b:=f(a)$.

First show that $f^{-1}(b)$ is closed.

Next, use the fact that that for every $x \in X$ there is a neighborhood in which $f$ is constant to show that $f^{-1}(b)$ is open.