📚 The CoCalc Library - books, templates and other resources
License: OTHER
"""This file contains code for use with "Think Stats",1by Allen B. Downey, available from greenteapress.com23Copyright 2014 Allen B. Downey4License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html5"""67from __future__ import print_function89import sys10from operator import itemgetter1112import first13import thinkstats2141516def Mode(hist):17"""Returns the value with the highest frequency.1819hist: Hist object2021returns: value from Hist22"""23return 0242526def AllModes(hist):27"""Returns value-freq pairs in decreasing order of frequency.2829hist: Hist object3031returns: iterator of value-freq pairs32"""33return []343536def main(script):37"""Tests the functions in this module.3839script: string script name40"""41live, firsts, others = first.MakeFrames()42hist = thinkstats2.Hist(live.prglngth)4344# test Mode45mode = Mode(hist)46print('Mode of preg length', mode)47assert mode == 39, mode4849# test AllModes50modes = AllModes(hist)51assert modes[0][1] == 4693, modes[0][1]5253for value, freq in modes[:5]:54print(value, freq)5556print('%s: All tests passed.' % script)575859if __name__ == '__main__':60main(*sys.argv)616263