33 lines
820 B
Python
33 lines
820 B
Python
def append(list1: list, list2: list) -> list:
|
|
return list1 + list2
|
|
def concat(lists: list[list]) -> list:
|
|
fin = []
|
|
for l in lists:
|
|
fin += l
|
|
return fin
|
|
def filter(function, list: list) -> list:
|
|
fin = []
|
|
for x in list:
|
|
if(function(x)):
|
|
fin.append(x)
|
|
return fin
|
|
def length(list: list):
|
|
return len(list)
|
|
def map(function, list: list) -> list:
|
|
fin = []
|
|
for x in list:
|
|
fin.append(function(x))
|
|
return fin
|
|
def foldl(function, list: list, initial: any) -> any:
|
|
acc = initial
|
|
for x in list:
|
|
acc = function(acc, x)
|
|
return acc
|
|
def foldr(function, list: list, initial: any) -> any:
|
|
acc = initial
|
|
for x in list[::-1]:
|
|
acc = function(acc, x)
|
|
return acc
|
|
def reverse(list: list) -> list:
|
|
return list[::-1]
|