]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-121977: Add tips for handling unhashable data (GH-122075) (#122077)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 21 Jul 2024 06:00:20 +0000 (08:00 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Jul 2024 06:00:20 +0000 (06:00 +0000)
gh-121977: Add tips for handling unhashable data (GH-122075)
(cherry picked from commit ebc18abbf34ff248764bda1a02db7f1c783b71e3)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
Doc/library/statistics.rst

index 0e44d9d92227e0500c7d299d14041ad1ee0dff48..ce1b8a112e852bd7925eee7e6fc1d95441beb786 100644 (file)
@@ -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