TITLE: Can an "almost injective'' function exist between compact connected metric spaces?
QUESTION [10 upvotes]: Let $\pi: X\to Y$ be a surjective continuous function between the compact, metric and connected spaces $X$, $Y$, and $Y_0 = \{y\in Y: \#\pi^{-1}(y)>1\}$. Suppose that:

$Y_0$ is dense in $Y$,
$Y\setminus Y_0$ is a dense $G_\delta$ in $Y$, and
for some constant $N<\infty$, we have  $\#\pi^{-1}(y) \leq N$ for all $y\in Y$.

My question is: can a function $\pi$ like this exist? Maybe I need more hypothesis on the topology of $X$ and $Y$.
Observe that the connectedness is crucial: Sturmian codings of irrational rotations of the circle are surjective continuous functions $\pi:K\to S^1$ from the Cantor set (a totally disconnected space) and the circle such that $\#\pi^{-1}(y) = 2$ for $y$ in a countable dense subset $Y_0 \subseteq S^1$ and $\#\pi^{-1}(y) = 1$ for $y \in S^1\setminus Y_0$.
Condition (3) is also needed: if $f\colon[0,1]\to[0,1]$ is the Thomae's function, $X = \{(x,y)\in[0,1]^2 : 0\leq y\leq f(x)\}$ is the subgraph of $f$, $\pi: X\to[0,1]$ is the projection onto the first coordinate, and $Y_0 := \{y\in Y: \#\pi^{-1}(y)>1\} = [0,1]\cap\mathbb{Q}$, then $\pi$ is continuous, $X$ is connected and (1),(2) hold, but $\pi(y)$ is an uncountable set when $y \in Y_0$.
After building these examples I am more convinced than at the beginning that $\pi$ must be injective.
I would appreciate any comment.

REPLY [6 votes]: A simple example is the Peano curve $f:[0,1]\to[0,1]^2$.
Specifically, here $Y_0=([0,1]\times T)\cup (T\times [0,1])$ where $T$ is the set of triadic rationals in $[0,1]$, a dense $F_\sigma$ with empty interior, so $Y\setminus Y_0=T^c\times T^c$ is a dense $G_\delta$. Check here for details. Note that here $N=4$ and, as per  Anton Petrunin's remark in a comment to the linked answer, one could modify the construction to make $N=3$.