Lists Tuples Problem 1 List Tuple Vice Versa Write Function Tuple Append Takes Input Tuple Q43814273
Need some help with Python Problems:

Lists and Tuples Problem 1: From a list to a tuple, and vice versa. Write a function tuple append which takes as input a tuple and an element, and appends the element at the end of the tuple, returning the resulting tuple. Note: we have to return a new tuple, as tuples cannot be modified in place. Hint: convert the tuple to a list, do the append, and then convert the result back to a tuple. [ ] def tuple_append (my_tuple, element): “””Appends element to the end of my_tuple, returning the result as a new tuple. # YOUR CODE HERE raise NotImplementedError() [] # Tests for tuple_append. # Be sure to run this cell, and every other test cell in the notebook, # to check that your code works. # If all tests pass, no output will appear; if a test fails, you’ll see an AssertionError. assert_equal (tuple_append((‘a’, ‘b’), ‘cat’), (‘a’, ‘b’, ‘cat’)) assert_equal (tuple_append( (), ()), ((),)) Show transcribed image text Lists and Tuples Problem 1: From a list to a tuple, and vice versa. Write a function tuple append which takes as input a tuple and an element, and appends the element at the end of the tuple, returning the resulting tuple. Note: we have to return a new tuple, as tuples cannot be modified in place. Hint: convert the tuple to a list, do the append, and then convert the result back to a tuple. [ ] def tuple_append (my_tuple, element): “””Appends element to the end of my_tuple, returning the result as a new tuple. # YOUR CODE HERE raise NotImplementedError() [] # Tests for tuple_append. # Be sure to run this cell, and every other test cell in the notebook, # to check that your code works. # If all tests pass, no output will appear; if a test fails, you’ll see an AssertionError. assert_equal (tuple_append((‘a’, ‘b’), ‘cat’), (‘a’, ‘b’, ‘cat’)) assert_equal (tuple_append( (), ()), ((),))
Expert Answer
Answer to Lists and Tuples Problem 1: From a list to a tuple, and vice versa. Write a function tuple append which takes as input a…
OR