Show that if $Y$ is path-connected, then the set $[I, Y]$ (the homotopy classes of maps from $I$ to $Y$) has a single element

Show that if $Y$ is path-connected, then the set $[I, Y]$ (the set of homotopy classes of maps from $I$ to $Y$) has a single element.

Now I understand that there are two similar questions, here : Show that a set of homotopy classes has a single element and here : If $Y$ is path-connected, then there is only one homotopy class of maps $[0,1] \to Y$

Now in both questions both of the people who asked the question picked two continuous maps $f_1, f_2 : I \to Y$ and showed that $f_1 \simeq c \simeq f_2$ where $c$ was some constant map.

But I don't see why we can't just choose an arbitrary continuous function $f : I \to Y$ and show that $f \simeq c$ where $c: I \to Y$ is some constant map, then we'd have thus shown that all continuous maps from $I$ to $Y$ are homotopic to $c$ (since $f$ was chosen arbitrarily) and thus we'd arrive at $[I, Y]= \{[c]\}$.

You can do this.

Note that the identity map on $I$ is homotopic to the constant map taking $I$ to $0$. Composing with $f$, $f$ is homotopic to the constant map taking $I$ to $f(0)$.

If $Y$ is path-connected and $y_0$ is your favourite point there, then there is a path from $f(0)$ to $y_0$. This induces a homotopy from the constant map taking $I$ to $f(0)$ and the constant map taking $I$ to $y_0$. Therefore $f$ is homotopic to the constant map taking $I$ to $y_0$.

One could replace $I$ by any contractible space in the foregoing.

Proof: Let $f : I \to Y$ be any continuous function. We will first show that $f$ is homotopic to the constant path taking all of $I$ to $f(0)$.

Define $c_{f(0)} : I \to Y$ by $c_{f(0)} = f(0) \ \ \ (\forall x \in X)$. We now construct a homotopy between $f$ and $c_{f(0)}$. Define $H: I \times I \to Y$ by $$H(x, t) = f((1-t)x).$$ Then $H$ is continuous and $H(x, 0) = f(x)$ and $H(x, 1) = f(0) = c_{f(0)}(x)$. Thus $f \simeq c_{f(0)}$.

Now note that although $c_{f(0)}$ is a constant path the definition of $c_{f(0)}$ depends on $f$ (and specifically the value of $f$ at $0$) so it would be wrong to conclude that $[I, Y] = \left\{\left[c_{f(0)}\right]\right\}$ at this point. We need to have a function independent of $f$ that is homotopic to $f$ to conclude that $[I, Y]$ consists of a single element.

To that end choose $p \in Y$ and define $k_p : I \to Y$ by $k_p(x) = p$ for all $x \in X$. We will now show that $c_{f(0)} \simeq k_p$ using path-connectedness of $Y$.

Since $Y$ is path-connected, there exists a path $\varphi : I \to Y$ such that $\varphi(0) = f(0)$ an $\varphi(1) = p$. Now define $G : I \times I \to Y$ by $G(x, t) = \varphi(t)$. Then $G$ is continuous because $G = \varphi \circ \pi$ (where $\pi : I \times I \to I$ is defined by $\pi(x, t) = t$) and $\varphi$ and $\pi$ are continuous functions. Note that $G(x, 0) = \varphi(0) = f(0) = c_{f(0)}(x)$ and $G(x, 1) = \varphi(1) = p =k_p(x)$. Hence $c_{f(0)} \simeq k_p$.

Since $f \simeq c_{f(0)}$ and $c_{f(0)} \simeq k_p$ we can conclude that $f \simeq k_p$. Thus since $f$ was chosen arbitrarily it follows that any continuous map from $I$ to $Y$ is homotopic to $k_p$ and thus we may conclude that $[I, Y] = \{[k_p]\}$ as desired. $\square$