From 2f002458ec960b5190b50014b8e88341b4783bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sat, 7 Sep 2019 18:50:32 +0200 Subject: [PATCH] Counter --- README.md | 3 ++- index.html | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 03289ce..bbc123b 100644 --- a/README.md +++ b/README.md @@ -94,8 +94,9 @@ value = .pop(key) # Removes item or raises KeyErro ### Counter ```python >>> from collections import Counter ->>> colors = ['red', 'blue', 'yellow', 'blue', 'red', 'blue'] +>>> colors = ['blue', 'red', 'blue', 'red', 'blue'] >>> counter = Counter(colors) +>>> counter['yellow'] += 1 Counter({'blue': 3, 'red': 2, 'yellow': 1}) >>> counter.most_common()[0] ('blue', 3) diff --git a/index.html b/index.html index 16c07dd..f68fc36 100644 --- a/index.html +++ b/index.html @@ -275,8 +275,9 @@ value = <dict>.setdefault(key, default=Nonefor k, v in <dict>.items() if k in keys} # Filters dictionary by keys.

Counter

>>> from collections import Counter
->>> colors = ['red', 'blue', 'yellow', 'blue', 'red', 'blue']
+>>> colors = ['blue', 'red', 'blue', 'red', 'blue']
 >>> counter = Counter(colors)
+>>> counter['yellow'] += 1
 Counter({'blue': 3, 'red': 2, 'yellow': 1})
 >>> counter.most_common()[0]
 ('blue', 3)