Say I have a regular polynomial like or .

Is there a way to extract the coefficient for the nth degree?

For example, if and I need the coefficient for (which is 5 in this case), is there some magic function g(f,n) which does:

g(f(x),2) = 5

?

(and similarly, g(f(x),3) would be 4, etc)