GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python-1/maths/average_mode.py at master · https-github-com-nzysoft/Python-1 Expand file tree/ Copy pathaverage_mode.pyMore file actions 32 lines (25 loc) · 935 Bytes / Copy pathaverage_mode.pyFile metadata and controls32 lines (25 loc) · 935 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 from typing import Any def mode(input_list: list) -> list[Any]: """This function returns the mode(Mode as in the measures of central tendency) of the input data. The input list may contain any Datastructure or any Datatype. >>> mode([2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2]) [2] >>> mode([3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 4, 2, 2, 2]) [2] >>> mode([3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 4, 4, 2, 2, 4, 2]) [2, 4] >>> mode(["x", "y", "y", "z"]) ['y'] >>> mode(["x", "x" , "y", "y", "z"]) ['x', 'y'] """ if not input_list: return [] result = [input_list.count(value) for value in input_list] y = max(result) # Gets the maximum count in the input list. # Gets values of modes return sorted({input_list[i] for i, value in enumerate(result) if value == y}) if __name__ == "__main__": import doctest doctest.testmod() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |