Skip to content

Commit b2458ca

Browse files
authored
Update utils.py
1 parent 651416e commit b2458ca

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ def is_in(elt, seq):
5959
"""Similar to (elt in seq), but compares with 'is', not '=='."""
6060
return any(x is elt for x in seq)
6161

62+
def mode(data):
63+
"""Return the most common data item. If there are ties, return any one of them."""
64+
[(item, count)] = Counter(data).most_common(1)
65+
return item
66+
6267
# ______________________________________________________________________________
6368
# argmin and argmax
6469

0 commit comments

Comments
 (0)