TITLE: continuous onto function from irrationals in [0,1] onto rationals in [0,1]
QUESTION [10 upvotes]: Give a continuous surjective function from the irrationals in $[0,1]$ onto the rationals in $[0,1]$. Can we at least prove the existence of such a function? I couldn't see a function off the top of my head. Here we assume $[0,1]\setminus\mathbb Q$ with its usual metric.

REPLY [2 votes]: The function $x\mapsto\left\lfloor\frac1x\right\rfloor$ maps the irrationals in $[0,1]$ continuously onto the countable discrete space $\mathbb N=\{1,2,3,\dots\}$, which can be mapped continuously onto any countable (nonempty) topological space, such as the space $\mathbb Q\cap[0,1]$.