How to override normal def function

I want to override normal def function which is not belongs to class or white listed one. is that possible?

Possible using monkey patch:

Please check the example:

@NCP does it work for normal python functions?

Check if it is on an event or not, if on event then try using doc_events.

@NCP no, its not a event. its get_transaction_list function which is inside erpnext.controllers.website_list_for_contact

then try with using monkey patch.