Say I have a regular polynomial like $\displaystyle 2x^3+5x^2+7x$ or $\displaystyle (x+x^2)^3$.

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

For example, if $\displaystyle f(x)=4x^3+5x^2-6x$ and I need the coefficient for $\displaystyle x^2$ (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)