Spivak's Limit Example Consider the function $f: (0, 1) \to \mathbb{Q}$ defined by
$$f(x) = \begin{cases}
0, & x\text{ irrational} \\
1/q, & x = p/q\text{ in lowest terms.}
\end{cases}$$
The problem is to show that $\lim\limits_{x \to a}f(x) = 0$, using $\delta$-$\epsilon$, for all $a \in (0, 1)$. That is, for all $\epsilon >0$ there is a $\delta > 0$ such that for all $x$ satisfying $0 < |x - a| < \delta$, $|f(x)-0| <\epsilon$.
If $x$ is irrational, this is trivial. Edit: as discussed in the comments, this isn't as trivial as I thought it was.
But what if $x$ is rational? Then $f(x) = 1/q$ as shown above, so
$$\left|\dfrac{1}{q}\right| < \epsilon\text{.}$$
I'm used to $\delta$-$\epsilon$ problems where I can "work backwards" to find $\delta$, but obviously $1/q$ isn't a function of $x$, and I'm lost as to what to do here. I sort of understand the discussion in Spivak, but I'm not quite getting how the discussion helps me find $\delta$, so I thought someone here could enlighten me.
As mentioned in the comments, I don't agree that this is a duplicate.

Let $a \in (0,1)$. 
For any $\epsilon > 0$, choose $N \in \mathbb{N}$ such that $1/N < \epsilon$.
There are only a finite number of rational numbers $r = p/q \in (0,1)$ in lowest terms with $q \leqslant N$.  Indeed, $r \in S_a =\{1/2, 1/3, 2/3, 1/4, 3/4, ..., (N-1)/N\}.$ 
Since $S_a$ is finite we can choose $\delta$ such that $0 <\delta < \min\{|r - a|: r  \in S_a\, r \neq a\}$.
Consider any $x   \in (0,1)$ with $ 0 < |x-a| < \delta$. If $x$ is irrational then $f(x)=0$ and $|f(x) - 0|= 0 < \epsilon.$
If $x$ is rational and $x = p/q$ in lowest terms, then $q > N$ and $|f(x) - 0| = 1/q < 1/N < \epsilon.$
Hence, $\lim_{x \to a}f(x) = 0.$
