Is it right to say,
There are more months in a year than days in a week.
My question is how to compare between two groups of words using 'than'?
Yes, this sentence sounds right to me. You've also constructed it correctly!
According to Merriam Webster, "than" is used to express the second member/second part of an unequal comparison.
In your sentence, I infer that there are 12 months in a year and 7 days in a week. Both numbers are not equal, so you're evidently on the right track!