Solution (source code)

= Solution

Enumerate $X=\{x_1,\ldots,x_n\}$ and $Y=\{y_1,\ldots,y_n\}$. The <universal property of a free group> gives an endomorphism
$$
\alpha:F(X)\longrightarrow F(X),qquad \alpha(x_i)=y_i.
$$
Since $Y$ generates, $\alpha$ is surjective. The finitely generated free group is residually finite and hence Hopfian by the preceding part, so $\alpha$ is an automorphism. An automorphism sends a free basis to a free basis; therefore $Y$ is a basis of $F(X)$.