From 2e31f0be2ca59573fdf506bde2f4023da19e8729 Mon Sep 17 00:00:00 2001 From: Patrik Tulach Date: Mon, 28 Sep 2026 20:38:10 +0200 Subject: [PATCH] u2 --- u2/list_ops.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 u2/list_ops.py diff --git a/u2/list_ops.py b/u2/list_ops.py new file mode 100644 index 0000000..4581d7e --- /dev/null +++ b/u2/list_ops.py @@ -0,0 +1,45 @@ +def append(list1, list2): + result = [] + for x in list1: + result = result + [x] + for x in list2: + result = result + [x] + +def concat(lists): + result = [] + for list in lists: + append(result, list) + return result + +def filter(function, list): + result = [] + for x in list: + if function(x): + result = result + [x] + return result + +def length(list): + lng = 0 + for i in list: + lng += 1 + return lng + +def map(function, list): + result = [] + for x in list: + if function(x) not in result: + result = result + [x] + return result + +def foldl(function, list, initial): + acc = initial + for x in list: + acc = function(acc, x) + return acc + +def foldr(function, list, initial): + return foldl(function, reverse(list), initial) + +def reverse(list): + result = list[::-1] + return result \ No newline at end of file