Update u2/list_ops.py
This commit is contained in:
parent
53f8c34cc1
commit
0d631f7eb5
@ -38,5 +38,13 @@ def foldl(function, list, initial):
|
||||
return acc
|
||||
|
||||
def foldr(function, list, initial):
|
||||
acc = initial
|
||||
for acc in list:
|
||||
acc = function(acc, item)
|
||||
return acc
|
||||
|
||||
def reverse(list):
|
||||
result = []
|
||||
for item in list:
|
||||
result = [item] + result
|
||||
return result
|
||||
Loading…
Reference in New Issue
Block a user