Обновить u2/list_ops.py
This commit is contained in:
parent
9460eeb97d
commit
4a2ddc7fb3
@ -5,3 +5,57 @@ def length(list):
|
||||
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 = fucntion(accamulator, item)
|
||||
return accamulator
|
||||
|
||||
|
||||
def foldr(function,list,initial):
|
||||
return foldl(function,reverse.(list),initial)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user