Derived sets - prove $(A \cup B)' = A' \cup B'$

I'm trying to prove $(A \cup B)' = A' \cup B'$ where $S'$ denotes the derived set of some subset $S$ of a topological space $X$. A derived set $S'$ of a set $S$ is the set of $x \in X$ such that $x$ is in the closure of $S-\{x\}$. I'm having troubling showing that $(A \cup B)' \subseteq A' \cup B'$.

What I've done so far: Suppose $x \in (A \cup B)'$. Then for any neighborhood $U$ of $x$ it follows that $U$ intersects $(A \cup B)-\{x\}$ so $U$ intersects $A-\{x\}$ or $B-\{x\}$. But I don't see why we couldn't have one neighborhood of $x$, $U_{1}$, which intersects $A-\{x\}$ but not $B-\{x\}$ and another neighborhood $U_{2}$ which does the opposite. In this case $x$ would be in neither $A'$ nor $B'$. We can say that $U_{1} \cap U_{2}$ is not only $\{x\}$ because then $\{x\}$ would be open contradicting $x \in (A \cup B)'$.


Ah, just noticed this is exactly Etienne's comment.


If all neighborhoods of $x$ intersect both $A\setminus\{x\}$ and $B\setminus\{x\}$, then we are done. Thus, assume to the contrary that a neighborhood $U$ intersects only $A\setminus\{x\}$. We will prove that $x\in A'$.

Suppose $V$ is any neighborhood of $x$ and note that $U\cap V$ is a neighborhood of $x$. Since $U\cap V\cap(B\setminus\{x\})\subseteq U\cap(B\setminus\{x\})=\emptyset$, it follows that $U\cap V$ intersects $A\setminus\{x\}$. Therefore, $V$ intersects $A\setminus\{x\}$ as desired.