From cd9773a882ac30d343fa25885ef618d0e311c387 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Wed, 4 Sep 2019 12:31:16 +0200 Subject: [PATCH] removes the smell of generators Fixes: #1 --- .../generators/hands_on/1_recognize_smell.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/notebook/generators/hands_on/1_recognize_smell.py b/notebook/generators/hands_on/1_recognize_smell.py index de84809..de71135 100644 --- a/notebook/generators/hands_on/1_recognize_smell.py +++ b/notebook/generators/hands_on/1_recognize_smell.py @@ -1,14 +1,14 @@ -for i in range(9): - if i % 3 == 0: - continue +def nondivisible(n,divide_by): + for i in range(n): + if i % divide_by != 0: + yield i + + +for i in nondivisible(9,3): print('Square is', i ** 2) -for j in range(5): - if j % 2 == 0: - continue - print('Cube is', j ** 3) +for i in nondivisible(5,2): + print('Cube is', i ** 3) -for k in range(13): - if k % 5 == 0: - continue - print('A' * k) +for i in nondivisible(13,5): + print('A' * i)