Property of free group from categorical definition I'm proving some properties about the free groups using the categorical definition, which is the following:

Let $X$ be a set, $L$ a group and $i:X\to L$ a map. The pair $(L,i)$ is free on $X$ if for every group $H$ and every map $f:X\to H$ there exists a unique group homomorphism $\varphi:G\to H$ such that $\varphi\circ i=f$.

I've already proved that 
(1) $i$ must be injective and that 
(2) if $(L_1,i_2)$ and $(L_2,i_2)$ are free on $X$ then there exists $\varphi:L_1\to L_2$ such that $\varphi\circ i_1=i_2$.
Now I'm stuck with the following:

If $|X|=|Y|$ and $(L_1,i_1)$ and $(L_2,i_2)$ are free on $X$ and $Y$ respectively, then $L_1\cong L_2$. 

I tried using a biyection $g:X\to Y$ and (2) to find $\varphi:L_1\to L_2$ which I can prove that is surjective. However, I cannot show that it is inyective outside $i_1(X)$, what can I do?
 A: Fix a bijection $g: X\rightarrow Y$ with inverse $h: Y\rightarrow X$. 
Then $f_1= i_2\circ g: X\rightarrow L_2$ defines a $\varphi_1: L_1\rightarrow L_2$ and similarly $f_2= i_1\circ h: Y\rightarrow L_1$ defines a $\varphi_2: L_2\rightarrow L_1$. 
The composition $\varphi_2\circ \varphi_1: L_1\rightarrow L_1$ is the homomorphisms corresponding to the mapping $id_X: X\rightarrow X$. As this map "extends" uniquely to a homomorphism $L_1\rightarrow L_1$ and the identity $id_{L_1}$ is obviously such a homomorphism, we have $\varphi_2\circ \varphi_1= id_{L_1}$. Similarly $\varphi_1\circ \varphi_2= id_{L_2}$, thus $\varphi_1$ is the desired isomorphism.
A: While there is already an accepted answer, I'd like to showcase a more algebraic solution to the problem which is not as common.

That $L, $ is the free group for $X$ means that there is a way to
“extend” maps from $X$ to homomorphisms from $L$,
$$     ⟨\_⟩ \,:\, (X → H) \,⟶\, (L → H)  $$
Such that this is indeed an extension when restricted to the elements of $X$,
$$ (0) \qquad ϕ ∘  = f  \quad≡\quad  ϕ = ⟨f⟩  $$
In (0) taking $ϕ$ to be $⟨f⟩$ yields
$$ (1) \qquad\qquad\qquad\qquad ⟨f⟩ ∘  = f $$
In (0) taking $ϕ, f$ to be $id, i$ yields
$$ (2) \qquad\qquad\qquad\;\;\;\;\qquad id = ⟨⟩ $$

Now suppose we are given $g : X ≅ Y$ where
$X, Y$ have free groups $L₁, ₁$ and $L₂, ₂$, then we
claim $⟨i₂ ∘ g⟩ : L₁ ≅ L₂$ with inverse $⟨₁ ∘ g⁻¹⟩$.
Indeed we can show this to be true with a simple calculation:
--omitting the subscripts--
  ⟨ ∘ g⟩ ∘ ⟨ ∘ g⁻¹⟩ = id
≡{ Using (2) with an aim to utilising (0) }
  ⟨ ∘ g⟩ ∘ ⟨ ∘ g⁻¹⟩ = ⟨⟩
≡{ Now in a position to utilise (0) }
  ⟨ ∘ g⟩ ∘ ⟨ ∘ g⁻¹⟩ ∘  = 
≡⟨ The only thing we can use is (1), so let's try it }
  ⟨ ∘ g⟩ ∘  ∘ g⁻¹ = 
≡⟨ Again the only thing we can use is (1), so let's try it }
   ∘ g ∘ g⁻¹ = 
≡{ Inverses and identity laws }
   = 
≡{ Reflexivity of equality }
  true

