Skip to content

Commit 5f46a72

Browse files
[3.12] gh-121977: Add tips for handling unhashable data (GH-122075) (#122077)
gh-121977: Add tips for handling unhashable data (GH-122075) (cherry picked from commit ebc18ab) Co-authored-by: Raymond Hettinger <[email protected]>
1 parent 966eff9 commit 5f46a72

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
@@ -408,6 +408,12 @@ However, for reading convenience, most of the examples show sorted sequences.
408408
>>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
409409
'red'
410410

411+
Only hashable inputs are supported. To handle type :class:`set`,
412+
consider casting to :class:`frozenset`. To handle type :class:`list`,
413+
consider casting to :class:`tuple`. For mixed or nested inputs, consider
414+
using this slower quadratic algorithm that only depends on equality tests:
415+
``max(data, key=data.count)``.
416+
411417
.. versionchanged:: 3.8
412418
Now handles multimodal datasets by returning the first mode encountered.
413419
Formerly, it raised :exc:`StatisticsError` when more than one mode was

0 commit comments

Comments
 (0)