add_to_list_if_not_present¶
- add_to_list_if_not_present(lst: list, element: Iterable)[source][source]¶
Add an element to a list if it is not present. Runs in O(1) time.
- Parameters:
lst (
list) – The list to add the element to.element (
Iterable) – The element to add to the list.
References
[1] https://www.youtube.com/watch?v=PXWL_Xzyrp4
Examples
>>> lst = [1, 2, 3] >>> add_to_list_if_not_present(lst, [3, 4, 5]) >>> lst [1, 2, 3, 4, 5]