Update u2/list_ops.py
This commit is contained in:
parent
efb3b0c2d4
commit
4133dc0af9
@ -12,39 +12,39 @@ def concat(lists):
|
||||
result = append(result, sublist)
|
||||
return result
|
||||
|
||||
def filter(function, list):
|
||||
def filter(function, lst):
|
||||
result = []
|
||||
for item in list:
|
||||
if function(item):
|
||||
result += [item]
|
||||
return result
|
||||
|
||||
def length(l):
|
||||
def length(lst):
|
||||
result = 0
|
||||
for item in l:
|
||||
for item in lst:
|
||||
result +=1
|
||||
return result
|
||||
|
||||
def map(function, list):
|
||||
def map(function, lst):
|
||||
result = []
|
||||
for item in list:
|
||||
for item in lst:
|
||||
result += [function(item)]
|
||||
return result
|
||||
|
||||
def foldl(function, list, initial):
|
||||
def foldl(function, lst, initial):
|
||||
acc = initial
|
||||
for item in list:
|
||||
for item in lst:
|
||||
acc = function(acc, item)
|
||||
return acc
|
||||
|
||||
def foldr(function, list, initial):
|
||||
def foldr(function, lst, initial):
|
||||
acc = initial
|
||||
for acc in list:
|
||||
for acc in lst:
|
||||
acc = function(acc, item)
|
||||
return acc
|
||||
|
||||
def reverse(list):
|
||||
def reverse(lst):
|
||||
result = []
|
||||
for item in list:
|
||||
for item in reverse(lst):
|
||||
result = [item] + result
|
||||
return result
|
||||
Loading…
Reference in New Issue
Block a user