TITLE: Does there exist a continuous onto function from $\mathbb{R}-\mathbb{Q}$ to $\mathbb{Q}$?
QUESTION [10 upvotes]: Does there exist a continuous onto function from $\mathbb{R}-\mathbb{Q}$ to  $\mathbb{Q}$?
(where domain is all irrational numbers)
I found many answers for contradicting the fact that there doesnt exist a continuous function which maps rationals to irrationals and vice versa.
But proving that thing was easier since our domain of definition of function was a connected set, we could use that connectedness or we could use the fact that rationals are countable and irrationals are uncountable.
But in this case those properties are not useful. I somehow think that baire category theorem might be useful but I am not good at using it.

REPLY [13 votes]: Yes. Say $E_n$ is the set of irrationals in the interval $(n,n+1)$. Say $(q_n)$ is an enumeration of $\Bbb Q$. Define $f(x)=q_n$ for $x\in E_n$.

REPLY [8 votes]: Yes, there exists such a function.
Biject $\mathbb{Q}$ with $\mathbb{Z}$ to get $\mathbb{Q} = \{q_n \mid n \in \mathbb{Z}\}$, and let $\mathbb{I}$ be the set of irrational numbers.
Define $I_n$ for $n \in \mathbb{Z}$ as $\mathbb{I} \cap (n, n+1)$. Then define $f(x) = q_n$ for all $x \in I_n$.
This is continuous, since for any irrational number in $I_n$, there is a small neighbourhood of it which is contained entirely within $I_n$ (because the "endpoints" of $I_n$ were chosen to be rational)