l
This commit is contained in:
parent
ddedc74526
commit
25b06bd8d6
57
fullu_2.py
Normal file
57
fullu_2.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
def append(list1, list2):
|
||||||
|
result = []
|
||||||
|
for item in list1 :
|
||||||
|
result = result + [item]
|
||||||
|
for item in list2 :
|
||||||
|
result = result + [item]
|
||||||
|
return result
|
||||||
|
def concat(lists):
|
||||||
|
result = []
|
||||||
|
for sublist in lists:
|
||||||
|
result = append(result, sublist)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def filter(function, list):
|
||||||
|
result = []
|
||||||
|
for item in list:
|
||||||
|
if function(item):
|
||||||
|
result += [item]
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def length(list):
|
||||||
|
count = 0
|
||||||
|
for _ in list:
|
||||||
|
count += 1
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
|
def map(function, list):
|
||||||
|
result = []
|
||||||
|
for item in list:
|
||||||
|
result += [function(item)]
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def foldl(function, list, initial):
|
||||||
|
accumulator = initial
|
||||||
|
for item in list:
|
||||||
|
accumulator = function(accumulator, item)
|
||||||
|
return accumulator
|
||||||
|
|
||||||
|
|
||||||
|
def foldr(function, list, initial):
|
||||||
|
accumulator = initial
|
||||||
|
index = length(list) - 1
|
||||||
|
while index >= 0:
|
||||||
|
accumulator = function(accumulator, list[index])
|
||||||
|
index -= 1
|
||||||
|
return accumulator
|
||||||
|
|
||||||
|
|
||||||
|
def reverse(list):
|
||||||
|
result = []
|
||||||
|
for item in list:
|
||||||
|
result = [item] + result
|
||||||
|
return result
|
||||||
@ -11,9 +11,11 @@ def concat(lists):
|
|||||||
result = append(result, item)
|
result = append(result, item)
|
||||||
return result
|
return result
|
||||||
def filter(function, list):
|
def filter(function, list):
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
if function(item) :
|
for item in list:
|
||||||
res = res + item
|
if function(item) :
|
||||||
|
res = res + [item]
|
||||||
return res
|
return res
|
||||||
def length(list) :
|
def length(list) :
|
||||||
counter = 0
|
counter = 0
|
||||||
@ -23,6 +25,20 @@ def length(list) :
|
|||||||
def map(function, list) :
|
def map(function, list) :
|
||||||
res = []
|
res = []
|
||||||
for item in list:
|
for item in list:
|
||||||
res = [function(item)] + res
|
res = res + [function(item)]
|
||||||
return res
|
return res
|
||||||
|
def foldl(function, list, initial):
|
||||||
|
final = initial
|
||||||
|
for item in list:
|
||||||
|
final = function(final, item)
|
||||||
|
return final
|
||||||
|
def foldr(function, list, initial):
|
||||||
|
final = initial
|
||||||
|
for item in reverse(list):
|
||||||
|
final = function(final, item)
|
||||||
|
return final
|
||||||
|
def reverse(list):
|
||||||
|
result = []
|
||||||
|
for item in list:
|
||||||
|
result = [item] + result
|
||||||
|
return result
|
||||||
Loading…
Reference in New Issue
Block a user