mirror of
https://git.hackliberty.org/Awesome-Mirrors/OSSU-computer-science.git
synced 2024-08-21 06:29:00 -06:00
add accumulate and filtered-accumulate patterns in 1.1.3
This commit is contained in:
parent
62b7aa9967
commit
575e44c837
Binary file not shown.
@ -20,4 +20,17 @@ for i in range(0, len(items), 1):
|
|||||||
if items[i] % 2 == 0:
|
if items[i] % 2 == 0:
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
# The accumulate pattern
|
||||||
|
total = 0
|
||||||
|
for i in range(0, len(items), 1):
|
||||||
|
total += items[i]
|
||||||
|
|
||||||
|
# The filtered-accumulate pattern
|
||||||
|
def sumEvens(items):
|
||||||
|
total = 0
|
||||||
|
for i in range(0, len(items), 1):
|
||||||
|
if items[i] % 2 == 0:
|
||||||
|
total += items[i]
|
||||||
|
return total
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user