TikZ: How to use draw options only for coordinates which exists / foreach-problem

I found a solution here: https://tex.stackexchange.com/a/85531/46023

\documentclass[border=2mm, tikz]{standalone}
\usepackage{tikz}
\begin{document}

\makeatletter
\long\def\ifcoorddefined#1#2#3{%
    \@ifundefined{pgf@sh@ns@#1}{#3}{#2}%
}
\makeatother

\begin{tikzpicture}[]
\coordinate[label=A](A) at (0,0);
\coordinate[label=B](B) at (2,3);
\coordinate[label=C](C) at (1,1);

\foreach \P in {A,B,C, X, Y, L, M}{
  \ifcoorddefined{\P}{  \draw[fill=pink] (\P) circle[radius=2pt];  }{}
}
\end{tikzpicture}

\end{document}

enter image description here

Tags:

Tikz Pgf