Write a function list_non_mutating_operations(items, item1, item2) that computes the
result of nine list operations without ever modifying items. Each operation starts
again from the original items.
Return a list holding the nine results, in this order:
items sorted in ascending order.items with item1 appended at the end.items with item2 inserted at index 3.items followed by the first three elements of items.items with the element at index 4 removed (if items has fewer than 5 elements,
an unchanged copy of items).items with the first occurrence of item2 removed (if item2 is not present,
an unchanged copy of items).items with the element at index 3 replaced by None (if items has 3 or fewer
elements, an unchanged copy of items).items with every even index (0, 2, 4, ...) replaced by None.items with every even index removed.Example
list_non_mutating_operations([3, 1, 2], 9, 1)
-> [[1, 2, 3], [3, 1, 2, 9], [3, 1, 2, 1], [3, 1, 2, 3, 1, 2],
[3, 1, 2], [3, 2], [3, 1, 2], [None, 1, None], [1]]
Implement this function:
def list_non_mutating_operations(items: list, item1, item2) -> list:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: items, item1, item2.
Input
[5, 3, 9, 1, 7]
10
3
Output
[[1, 3, 5, 7, 9], [5, 3, 9, 1, 7, 10], [5, 3, 9, 3, 1, 7], [5, 3, 9, 1, 7, 5, 3, 9], [5, 3, 9, 1], [5, 9, 1, 7], [5, 3, 9, None, 7], [None, 3, None, 1, None], [3, 1]]