Problem 2 Write Function Listdiff Takes Input Two Lists L1 12 Output Produced Follows Ever Q43814280
Need some help with Python Problem:

Problem 2 Write a function list_diff that takes as input two lists, l1 and 12. The output is produced as follows. For every element x of li: • if El2, strike out x both from ly and from 12. • if € 12, add x to the resulting string. Thus, list_diff([‘a’, ‘b’, ‘b’, ‘c’], [‘b’, ‘c’,’d’]) returns [‘a’, ‘b’] and list_diff([‘a’, ‘a’, ‘b’, ‘b’, ‘b’], [‘a’, ‘a’, ‘b’, ‘b’, ‘c’]) returns [‘b’] The implementation should leave the input lists unchanged. (Recall that lists are mutable, not immutable like tuples are!) You can achieve this by copying the input arguments before using them; you can obtain a copy of a list 1 with list(1). [] def list_diff(11, 12): “”‘”The implementation takes 8 lines of code.” # YOUR CODE HERE raise NotImplementedError() [] # Tests for list_diff assert_equal(list_diff([‘a’, ‘b’, ‘b’, ‘c’], [‘b’, ‘c’,’d’]), [‘a’, ‘b’]) assert_equal(list_diff([‘a’, ‘a’, ‘b’, ‘b’, ‘b’], [‘a’, ‘a’, ‘b’, ‘b’, ‘c’]), [‘b’]) [] # Further tests for list_diff 11 = [‘a’, ‘b’, ‘c’, ‘c’,’d’] 12 = [‘b’, ‘a’, ‘a’, ‘c’] assert_equal(list_diff(11, 12), [‘c’,’d’]) assert_equal(11, [‘a’, ‘b’, ‘c’, ‘c’,’d’]) assert_equal(12, [‘b’, ‘a’, ‘a’, ‘c’]) Show transcribed image text Problem 2 Write a function list_diff that takes as input two lists, l1 and 12. The output is produced as follows. For every element x of li: • if El2, strike out x both from ly and from 12. • if € 12, add x to the resulting string. Thus, list_diff([‘a’, ‘b’, ‘b’, ‘c’], [‘b’, ‘c’,’d’]) returns [‘a’, ‘b’] and list_diff([‘a’, ‘a’, ‘b’, ‘b’, ‘b’], [‘a’, ‘a’, ‘b’, ‘b’, ‘c’]) returns [‘b’] The implementation should leave the input lists unchanged. (Recall that lists are mutable, not immutable like tuples are!) You can achieve this by copying the input arguments before using them; you can obtain a copy of a list 1 with list(1). [] def list_diff(11, 12): “”‘”The implementation takes 8 lines of code.” # YOUR CODE HERE raise NotImplementedError() [] # Tests for list_diff assert_equal(list_diff([‘a’, ‘b’, ‘b’, ‘c’], [‘b’, ‘c’,’d’]), [‘a’, ‘b’]) assert_equal(list_diff([‘a’, ‘a’, ‘b’, ‘b’, ‘b’], [‘a’, ‘a’, ‘b’, ‘b’, ‘c’]), [‘b’]) [] # Further tests for list_diff 11 = [‘a’, ‘b’, ‘c’, ‘c’,’d’] 12 = [‘b’, ‘a’, ‘a’, ‘c’] assert_equal(list_diff(11, 12), [‘c’,’d’]) assert_equal(11, [‘a’, ‘b’, ‘c’, ‘c’,’d’]) assert_equal(12, [‘b’, ‘a’, ‘a’, ‘c’])
Expert Answer
Answer to Problem 2 Write a function list_diff that takes as input two lists, l1 and 12. The output is produced as follows. For ev…
OR