Write a function diff(list1, list2). When called with list arguments list1 and list2, it should return a new list dlist
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write a function diff(list1, list2). When called with list arguments list1 and list2, it should return a new list dlist
Write a function diff(list1, list2). When called with list arguments list1 and list2, it should return a new list dlist without duplicates, with dlist containing each top-level element of list1 that does NOT Occur as a top-level element in list2. Also, dlist should contain each top-level element of list2 that does NOT occur as a top- level element in list1. Use == to do your comparisons. Define a main() function which reads two lists list1 and list2 from the user: use the eval() function to convert each of these inputs into actual lists. Then call diff(list1, list2) and print the returned result. Example: diff([1,4,2,1,3,2],[1,4,5]) should return [2,3,5), since 2 and 3 occur in the first list, but not in the second, and 5 occurs only in the second . Note that although 2 occurs twice in the first list, it appears only once in the returned list: no duplicates should be returned.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!