Topology - $f$ is continuous iff $f$ is constant Let $X_1$ be with the trivial topology, $X_2$ be Hausdorff, $f:X_1 \rightarrow X_2$ a function. Then $f$ is continuous $\iff f$ is constant. I'm not sure that my proof is correct so would appreciate a check on it. I've coloured in red the parts that I'm not sure of in particular.
Proof:

$\implies$
Assume that if $x,y \in X_1$, then $f(x) \neq f(y)$. Since $X_2$ is Hausdorff, $\exists$ open $U$ such that $f(x) \in U, f(y) \notin U$. Since $f$ is continuous, we have that $f^{-1}(U)$ is open in $X_1$. Since $X_1$ is the trivial topology we have that $f^{-1}(U) \in \{\varnothing, X_1\}$. ${\color{#c00}{\text{If }f^{-1}(U) = \varnothing, \text{ then } U = \varnothing. \text{ But then } f(x) \notin U, \text{ which is a contradiction. If } f^{-1}(U) = X_1, \text{ then } U = X_2. \text{ But then } f(y) \in U, \text{ which is a contradiction.}}}$ Hence, $f(x) = f(y)$, i.e. $f$ is constant.
$\impliedby$
Let $f(x) = c \in X_2$, for all $x \in X_1$. Then there exists an open $U \subset X_2$ such that $c \in U$. ${\color{#c00}{\text{Then } f^{-1}(U) = \{x \in X_1 : f(x) \in U\} = X_1, \text{ (I'm really not sure about this since I've used nowhere that } X_2 \text{ is Hausdorff.)}}}$

 A: Your proof is correct, but a bit inelegant. That is, at least in part, owed to the given rather strong conditions. You tried to use the full given conditions although weaker conditions suffice.
Let's start with your second direction, every constant map is continuous. That holds regardless of the topologies on domain and codomain. Because, for a constant map $f \colon X_1 \to X_2$ we have
$$f^{-1}(A) \in \{ \varnothing,\, X_1\}$$
for all $A \subset X_2$. So all preimages are open for constant maps, in particular preimages of open sets.
To conclude that a non-constant map $f \colon X_1 \to X_2$, where $X_1$ is endowed with the indiscrete (trivial) topology cannot be continuous, it suffices to require that $X_2$ is a $T_0$ space, i.e. for any two distinct $x,y \in X_2$ there is an open set with $x\in U$ but $y\notin U$ or $y\in U$ but $x\notin U$. Then if we have $p,q \in X_1$ with $f(p) \neq f(q)$, there is an open subset $U$ of $X_2$ containing exactly one of $f(p)$ and $f(q)$, and thus $\varnothing \subsetneq f^{-1}(U) \subsetneq X_1$, so $f^{-1}(U)$ is not open.
