It is always possible to construct continuous function? Given $D \subset X \subset \mathbb R$, I want to create a function $f: X \rightarrow \mathbb R$ such that
(1) it's continuous
(2) it has fixed value for every element of D (different values)
When it is possible?
For example, if D is finite, is certainly possible (with a polynomial, for example). It is possible even if $D = \mathbb N$ and, for example, I want that f(n) = n for every $n \in \mathbb N$. Or it is possible for every D if I fixed a single value for every element. 
It's (obviously) not possible if I choose $D = \mathbb R$ and I set the values such that the function is discontinuous. It's also not possible if I choose $D = \{x_n\}$ with $x_0 = 0, x_1=0.9, x_2=0.99 ... x_n \rightarrow 1$ and I set $f(x_n) = n$, in fact $f(1) = lim_{n \to \infty}f(x_n) = \infty$ (it would be continuous in [0, 1)?)
I think it is a well-known question, but I don't know how to search it. 
Thanks in advance.
(edit: and what if I work in a generic topological space, not $\mathbb R$?)
 A: It's possible as long as it's not obviously impossible. That is, as long as there aren't two convergent sequences $x_n, y_n$ in $D$ (with limits not necessarily in $D$) such that $\lim x_n = \lim y_n$ but either one of $f(x_n)$ or $f(y_n)$ doesn't converge or $\lim f(x_n)\neq \lim f(y_n)$ (where $f$ is the function we're trying to extend to a continuous function on $\mathbb R$).
To see this, simply define $f(x)=\lim f(x_n)$ on $\overline D$, where $x_n\to x$ is a sequence in $D$. By our assumption this is a valid definition, and it extends $f$ continuously to a closed set. Any continuous function on a closed set can be extended to $\mathbb R$.
This may not work in other metric spaces, or even in $\mathbb R^n$, since the linked proof relies on a very one-dimensional specific property of open sets. It works in any metric space in which continuous functions on closed sets can always be extended. Such spaces are the subject of the Tietze extension theorem (thanks Daniel Schepler in the comments).
