import cppy.cp_util as util import operator # 工具函数 def extract_words(path_to_file): return util.extract_file_words(path_to_file) def frequencies(word_list): return util.get_frequencies(word_list) s = ' lambda word_freq: '+ \ ' sorted(word_freq.items(), key=operator.itemgetter(1), reverse=True) ' exec( 'mysort = ' + s ) # s 可以是读文件,也可以网络发过来的代码 if __name__ == '__main__': word_freq = frequencies(extract_words( util.testfilepath )) word_freq = locals()['mysort'](word_freq) util.print_word_freqs(word_freq)