From 5cd53f60d08aa027ebc4416b10b9fe052d2597a5 Mon Sep 17 00:00:00 2001 From: sagar-sehgal Date: Wed, 23 Jan 2019 04:11:14 +0530 Subject: [PATCH 1/2] improved the count function in utils.py --- utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils.py b/utils.py index ab6aa1032..e93659866 100644 --- a/utils.py +++ b/utils.py @@ -31,14 +31,14 @@ def removeall(item, seq): return [x for x in seq if x != item] -def unique(seq): # TODO: replace with set +def unique(seq): """Remove duplicate elements from seq. Assumes hashable elements.""" return list(set(seq)) -def count(seq): # TODO: replace with quantify +def count(seq): """Count the number of items in sequence that are interpreted as true.""" - return sum(bool(x) for x in seq) + return sum(map(bool,seq)) def multimap(items): """Given (key, val) pairs, return {key: [val, ....], ...}.""" From 264ef1a1b4334c182c661faf31855608fa403fe1 Mon Sep 17 00:00:00 2001 From: sagar-sehgal Date: Fri, 25 Jan 2019 19:44:34 +0530 Subject: [PATCH 2/2] updated according to PEP style --- utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.py b/utils.py index e93659866..a7d3fef2a 100644 --- a/utils.py +++ b/utils.py @@ -38,7 +38,7 @@ def unique(seq): def count(seq): """Count the number of items in sequence that are interpreted as true.""" - return sum(map(bool,seq)) + return sum(map(bool, seq)) def multimap(items): """Given (key, val) pairs, return {key: [val, ....], ...}."""