An identity for generating functions is proved in this paper. A novel method to compute the number of restricted lattice paths is developed on the basis of this identity. The method employs a difference equation with non-constant coefficients. Dyck paths, Schr¨oder paths, Motzkins path and other paths are computed to illustrate this method