Final clean fix for list_ops
This commit is contained in:
parent
b724b82aad
commit
bdd1eb5208
@ -6,46 +6,42 @@ def append(list1, list2):
|
|||||||
pusti.append(exc)
|
pusti.append(exc)
|
||||||
return pusti
|
return pusti
|
||||||
|
|
||||||
def concat(list):
|
def concat(lists):
|
||||||
pusti = []
|
pusti = []
|
||||||
for gns in list:
|
for gns in lists:
|
||||||
pusti.extend(gns)
|
pusti.extend(gns)
|
||||||
return pusti
|
return pusti
|
||||||
|
|
||||||
def filter(function, list):
|
def filter(function, list):
|
||||||
pusti = []
|
pusti = []
|
||||||
for gns in list:
|
for gns in list:
|
||||||
if function(gns):
|
if function(gns):
|
||||||
pusti.append(gns)
|
pusti.append(gns)
|
||||||
return pusti
|
return pusti
|
||||||
|
|
||||||
def length(list):
|
def length(list):
|
||||||
pocatok = 0
|
pocatok = 0
|
||||||
for gns in list:
|
for gns in list:
|
||||||
pocatok = pocatok + 1
|
pocatok = pocatok + 1
|
||||||
return pocatok
|
return pocatok
|
||||||
|
|
||||||
def map(function, list):
|
def map(function, list):
|
||||||
pusti = []
|
pusti = []
|
||||||
for gns in list:
|
|
||||||
function(gns)
|
|
||||||
pusti.append(function(gns))
|
|
||||||
return pusti
|
|
||||||
|
|
||||||
def foldl(function, accumulator, initial):
|
|
||||||
accumulator = initial
|
|
||||||
for gns in list:
|
|
||||||
accumulator = function(accumulator, gns)
|
|
||||||
return accumulator
|
|
||||||
|
|
||||||
def foldr(function, initial, acc):
|
|
||||||
acc = initial
|
|
||||||
for gns in list[::-1]:
|
|
||||||
acc = function(gns, acc)
|
|
||||||
return acc
|
|
||||||
|
|
||||||
def reverse(list):
|
|
||||||
pusti = []
|
|
||||||
for gns in list:
|
for gns in list:
|
||||||
pusti.append(gns)
|
pusti.append(function(gns))
|
||||||
return pusti[::-1]
|
return pusti
|
||||||
|
|
||||||
|
def foldl(function, list, initial):
|
||||||
|
accumulator = initial
|
||||||
|
for gns in list:
|
||||||
|
accumulator = function(accumulator, gns)
|
||||||
|
return accumulator
|
||||||
|
|
||||||
|
def foldr(function, list, initial):
|
||||||
|
acc = initial
|
||||||
|
for gns in list[::-1]:
|
||||||
|
acc = function(gns, acc)
|
||||||
|
return acc
|
||||||
|
|
||||||
|
def reverse(list):
|
||||||
|
return list[::-1]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user