Skip to content

Commit 774c7b1

Browse files
[3.13] gh-121977: Add tips for handling unhashable data (GH-122075) (#122076)
gh-121977: Add tips for handling unhashable data (GH-122075) (cherry picked from commit ebc18ab) Co-authored-by: Raymond Hettinger <[email protected]>
1 parent 7fc1006 commit 774c7b1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Doc/library/statistics.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ However, for reading convenience, most of the examples show sorted sequences.
485485
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
486486
'red'
487487

488+
Only hashable inputs are supported. To handle type :class:`set`,
489+
consider casting to :class:`frozenset`. To handle type :class:`list`,
490+
consider casting to :class:`tuple`. For mixed or nested inputs, consider
491+
using this slower quadratic algorithm that only depends on equality tests:
492+
``max(data, key=data.count)``.
493+
488494
.. versionchanged:: 3.8
489495
Now handles multimodal datasets by returning the first mode encountered.
490496
Formerly, it raised :exc:`StatisticsError` when more than one mode was

0 commit comments

Comments
 (0)