Skip to content
Permalink
Browse files

Added correct code sample for "Beautiful is better than ugly". Thanks…

… to Anshu Kumar!
  • Loading branch information
WoLpH committed Jul 18, 2016
1 parent cad6751 commit f7ec4fc2480614ea8369f7d27a99b22046e2a780
@@ -0,0 +1,33 @@
>>> def filter_modulo(items, modulo):
... output_items = []
... for i in range(len(items)):
... if items[i] % modulo:
... output_items.append(items[i])
... return output_items
...
>>> filter_modulo(range(10), 3)
[1, 2, 4, 5, 7, 8]

>>> filter_modulo = lambda i, m: [i[j] for j in range(len(i)) if i[j] % m]
>>> filter_modulo(range(10), 3)
[1, 2, 4, 5, 7, 8]

>>> filter_modulo = lambda items, modulo: [items[i] for i in range(len(items))
... if items[i] % modulo]
>>> filter_modulo(range(10), 3)
[1, 2, 4, 5, 7, 8]

>>> def filter_modulo(items, modulo):
... for item in items:
... if item % modulo:
... yield item
...
>>> list(filter_modulo(range(10), 3))
[1, 2, 4, 5, 7, 8]
File renamed without changes.
File renamed without changes.

0 comments on commit f7ec4fc

Please sign in to comment.
You can’t perform that action at this time.