write term_frequency function for python