TITLE: No continuous function switches $\mathbb{Q}$ and the irrationals
QUESTION [50 upvotes]: Is there a way to prove the following result using connectedness?
Result:
Let $J=\mathbb{R} \setminus \mathbb{Q}$ denote the set of irrational numbers. There is no continuous map $f: \mathbb{R} \rightarrow \mathbb{R}$ such that $f(\mathbb{Q}) \subseteq J$ and $f(J) \subseteq \mathbb{Q}$.
http://planetmath.org/encyclopedia/ThereIsNoContinuousFunctionThatSwitchesTheRationalNumbersWithTheIrrationalNumbers.html

REPLY [2 votes]: Suppose such a continuous function exists. $f(\Bbb R)$ is connected, and hence uncountable. Then, $f(\Bbb Q)$ is countable because $\Bbb Q$ is so. Moreover, $f(\Bbb R\setminus\Bbb Q)$ is countable since it is contained in $\Bbb Q$. This is a contradiction.