netlist_carpentry.utils.custom_list
¶
Module for a custom list class, with some extensions to the normal Python list.
Classes:
CustomList
¶
Bases: List[V]
Methods:
-
flatten–This function flattens (expands) the current list.
-
add–Adds an object to a list, if no equal object is already present.
-
remove–Removes an element from a list if it exists in the list.
flatten
¶
flatten() -> List[V]
This function flattens (expands) the current list.
Returns:
-
Self(List[V]) –A flat list containing all elements from the input list, including those in sublists.
add
¶
add(object: V, locked: bool = False, allow_duplicates: bool = False) -> V
Adds an object to a list, if no equal object is already present.
Parameters:
-
(object¶object) –The object to be added.
-
(locked¶bool, default:False) –Whether the target list can be modified. Useful to prevent changes e.g. in modules marked as locked. Defaults to False.
-
(allow_duplicates¶bool, default:False) –Whether the target list may contain duplicates, i.e. multiple equal values. Defaults to False. If True, this method behaves similar to
list.append.
Returns:
-
V(V) –The object that was successfully added.
Raises:
-
IdentifierConflictError–If such an object already exists in this list.
-
ObjectLockedError–If "locked" is set to
True, i.e. the list cannot be modified currently.
remove
¶
Removes an element from a list if it exists in the list.
Parameters:
-
(object¶object) –The element to be removed.
-
(locked¶bool, default:False) –Whether the target list can be modified. Useful to prevent changes e.g. in modules marked as locked. Defaults to False.
Raises:
-
ObjectNotFoundError–If no such object exists in this list.
-
ObjectLockedError–If "locked" is set to
True, i.e. the list cannot be modified currently.