62 lines
1018 B
Python
62 lines
1018 B
Python
def length(list):
|
|
count = 0
|
|
for item in list:
|
|
count +=1
|
|
return count
|
|
|
|
|
|
def append(list1, list2):
|
|
result = []
|
|
for item in list1:
|
|
result.append(item)
|
|
for item in list2:
|
|
result.append(item)
|
|
return result
|
|
|
|
|
|
def concat(lists):
|
|
result = []
|
|
for box in lists:
|
|
for item in box:
|
|
result.append(item)
|
|
return result
|
|
|
|
|
|
def filter(function, list):
|
|
result = []
|
|
for item in list:
|
|
if function(item):
|
|
result.append(item)
|
|
return result
|
|
|
|
|
|
def map(function,list):
|
|
result = []
|
|
for item in list:
|
|
result.append(function(item))
|
|
return result
|
|
|
|
|
|
def reverse(list):
|
|
result = []
|
|
for item in list:
|
|
result = [item] + result
|
|
return result
|
|
|
|
|
|
def foldl(function,list,initial):
|
|
accamulator = initial
|
|
for item in list:
|
|
accamulator = function(accamulator, item)
|
|
return accamulator
|
|
|
|
|
|
def foldr(function,list,initial):
|
|
return foldl(function,reverse(list),initial)
|
|
|
|
|
|
|
|
|
|
|
|
|