Consider the following example:
\documentclass{article}
\usepackage{xparse}
% http://tex.stackexchange.com/a/246924/15874
\ExplSyntaxOn
\NewDocumentCommand{\countlist}{m}{\clist_count:n{#1}}
\ExplSyntaxOff
\newcommand*\liste{
\marsvin,
\hund,
\kat,
\hoens,
\hest,
\fisk,
\fugl,
\kanin,
\oerkenrotte,
\slange,
\gris,
\hamster
}
\newcommand*\str{\countlist{\liste}}
\begin{document}
% data
\def\marsvin{1}
\def\hund{12}
\def\kat{14}
\def\hoens{2}
\def\hest{5}
\def\fisk{3}
\def\fugl{2}
\def\kanin{2}
\def\oerkenrotte{1}
\def\slange{1}
\def\gris{1}
\def\hamster{1}
Number of elements: \str
\end{document}
In this example \str prints the number 1 but I would like it to print 12.
I guess the problem is that function counts the number of lists and not the number of elements in the list.
How do I solve this problem?
P.S. If I use
\newcommand*\str{\countlist{
\marsvin,
\hund,
\kat,
\hoens,
\hest,
\fisk,
\fugl,
\kanin,
\oerkenrotte,
\slange,
\gris,
\hamster
}}
everything is fine.

