Update u2/list_ops.py

This commit is contained in:
Roman Dmytruk 2026-10-01 14:22:24 +00:00
parent 53f8c34cc1
commit 0d631f7eb5

View File

@ -38,5 +38,13 @@ def foldl(function, list, initial):
return acc return acc
def foldr(function, list, initial): def foldr(function, list, initial):
acc = initial
for acc in list:
acc = function(acc, item)
return acc
def reverse(list): def reverse(list):
result = []
for item in list:
result = [item] + result
return result