This commit is contained in:
Patrik Tulach 2026-09-28 20:38:10 +02:00
parent fd4dfee6d8
commit 2e31f0be2c

45
u2/list_ops.py Normal file
View File

@ -0,0 +1,45 @@
def append(list1, list2):
result = []
for x in list1:
result = result + [x]
for x in list2:
result = result + [x]
def concat(lists):
result = []
for list in lists:
append(result, list)
return result
def filter(function, list):
result = []
for x in list:
if function(x):
result = result + [x]
return result
def length(list):
lng = 0
for i in list:
lng += 1
return lng
def map(function, list):
result = []
for x in list:
if function(x) not in result:
result = result + [x]
return result
def foldl(function, list, initial):
acc = initial
for x in list:
acc = function(acc, x)
return acc
def foldr(function, list, initial):
return foldl(function, reverse(list), initial)
def reverse(list):
result = list[::-1]
return result