Skip to content

Commit

Permalink
[3.12] pythongh-121977: Add tips for handling unhashable data (python…
Browse files Browse the repository at this point in the history
…GH-122075) (python#122077)

pythongh-121977: Add tips for handling unhashable data (pythonGH-122075)
(cherry picked from commit ebc18ab)

Co-authored-by: Raymond Hettinger <[email protected]>
  • Loading branch information
miss-islington and rhettinger authored Jul 21, 2024
1 parent 966eff9 commit 5f46a72
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Doc/library/statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ However, for reading convenience, most of the examples show sorted sequences.
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
'red'

Only hashable inputs are supported. To handle type :class:`set`,
consider casting to :class:`frozenset`. To handle type :class:`list`,
consider casting to :class:`tuple`. For mixed or nested inputs, consider
using this slower quadratic algorithm that only depends on equality tests:
``max(data, key=data.count)``.

.. versionchanged:: 3.8
Now handles multimodal datasets by returning the first mode encountered.
Formerly, it raised :exc:`StatisticsError` when more than one mode was
Expand Down

0 comments on commit 5f46a72

Please sign in to comment.