summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/list.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/python/vyos/utils/list.py b/python/vyos/utils/list.py
index 931084e7c..ea4bcd3ba 100644
--- a/python/vyos/utils/list.py
+++ b/python/vyos/utils/list.py
@@ -18,3 +18,26 @@ def is_list_equal(first: list, second: list) -> bool:
if len(first) != len(second) or len(first) == 0:
return False
return sorted(first) == sorted(second)
+
+
+def list_strip(lst: list, sub: list, right: bool = False) -> list:
+ """Remove list 'sub' from beginning (right=False), resp., end of list 'lst'"""
+
+ if not right:
+ while sub:
+ if lst[:1] == sub[:1]:
+ lst = lst[1:]
+ sub = sub[1:]
+ else:
+ lst = []
+ sub = []
+ else:
+ while sub:
+ if lst[-1:] == sub[-1:]:
+ lst = lst[:-1]
+ sub = sub[:-1]
+ else:
+ lst = []
+ sub = []
+
+ return lst