DRY
There are two acronyms that almost every programming student will have heard of. The first is DRY. This acronym urges us to write a piece of code only once and then reuse it as much as possible. If we create small, generic functions, we can prevent copy-pasting the same few lines over our whole code base.
But I should also warn you not to overdo it. Sometimes, it is okay to have a little bit of duplicate code that is better tailored to a particular scenario than to hack multiple scenarios into one piece of code. Use your best judgment.