From ef48d845cbfcad5fd9d55614ee4a253152be9a33 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 14 Aug 2024 11:47:08 +0100 Subject: use generator expression, remove intermediate list --- challenge-282/steven-wilson/python/ch-2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'challenge-282/steven-wilson/python') diff --git a/challenge-282/steven-wilson/python/ch-2.py b/challenge-282/steven-wilson/python/ch-2.py index 199cffc157..afc62d82a7 100644 --- a/challenge-282/steven-wilson/python/ch-2.py +++ b/challenge-282/steven-wilson/python/ch-2.py @@ -21,7 +21,7 @@ def changing_keys(string): if not all(c.isalpha() for c in string): raise ValueError('User should type an aphabetic string') - return len([item for _, item in groupby(string.casefold())]) - 1 + return sum(1 for _ in groupby(string.casefold())) - 1 if __name__ == "__main__": -- cgit