Here is a statement from a textbook that I'm referring to:
From a set containing $l$ things of one kind, $m$ things of a different kind, $n$ things of a third kind and so on, the number of ways of choosing $r$ things out of this set of objects is the coefficient of $x^r$ in the expansion of $$(1+x+x^2+x^3+...+x^l)(1+x+x^2+x^3+...+x^m)(1+x+x^2+x^3+...+x^n).$$
Can someone please explain the intuition behind this? How can it be derived?
The expansion of that expression does the same as picking items from the groups. You can expand the expression in one huge step: choosing one sub-expression from each bracket and summing up all possibilities of how you can do it. Each sub-expression refers to how many things you choose from given group. $1$ means not choosing anything, $x$ means choose 1 thing, $x^2$ means choose two things etc.. And the exponent of x will show you how many things you have already picked.
Noone forces you to perform the expansion in one step, so you can do it in multiple steps and you will receive the same.
This formula allows you to add more constraints. For example, if you don't want the things l being selected exactly three times, you delete the $x^3$ from corresponding bracket. Or if you want each item being chosen at least once, you delete the $1$ from all brackets.