From 321760e14903e61f78db1c3e4693191f1bbecb82 Mon Sep 17 00:00:00 2001 From: Maksym Kurets Date: Wed, 30 Sep 2026 23:04:15 +0200 Subject: [PATCH] All list ops complete --- u2/ list_ops.py | 55 +++++++++++++++++-- u2/.ipynb_checkpoints/ list_ops-checkpoint.py | 55 +++++++++++++++++-- 2 files changed, 98 insertions(+), 12 deletions(-) diff --git a/u2/ list_ops.py b/u2/ list_ops.py index a4049ea..b7e2926 100644 --- a/u2/ list_ops.py +++ b/u2/ list_ops.py @@ -1,8 +1,51 @@ def append(list1, list2): - pusti = [] -for gns in list1: - pusti.append(gns) - for exc in list2: - pusti.append(exc) + pusti = [] + for gns in list1: + pusti.append(gns) + for exc in list2: + pusti.append(exc) + return pusti -return pusti \ No newline at end of file + def concat(list): + pusti = [] + for gns in list: + pusti.extend(gns) + return pusti + + def filter(function, list): + pusti = [] + for gns in list: + if function(gns): + pusti.append(gns) + return pusti + + def length(list): + pocatok = 0 + for gns in list: + pocatok = pocatok + 1 + return pocatok + + def map(function, list): + 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: + pusti.append(gns) + return pusti[::-1] \ No newline at end of file diff --git a/u2/.ipynb_checkpoints/ list_ops-checkpoint.py b/u2/.ipynb_checkpoints/ list_ops-checkpoint.py index a4049ea..b7e2926 100644 --- a/u2/.ipynb_checkpoints/ list_ops-checkpoint.py +++ b/u2/.ipynb_checkpoints/ list_ops-checkpoint.py @@ -1,8 +1,51 @@ def append(list1, list2): - pusti = [] -for gns in list1: - pusti.append(gns) - for exc in list2: - pusti.append(exc) + pusti = [] + for gns in list1: + pusti.append(gns) + for exc in list2: + pusti.append(exc) + return pusti -return pusti \ No newline at end of file + def concat(list): + pusti = [] + for gns in list: + pusti.extend(gns) + return pusti + + def filter(function, list): + pusti = [] + for gns in list: + if function(gns): + pusti.append(gns) + return pusti + + def length(list): + pocatok = 0 + for gns in list: + pocatok = pocatok + 1 + return pocatok + + def map(function, list): + 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: + pusti.append(gns) + return pusti[::-1] \ No newline at end of file