Page 1 of 1

Write a function diff(list1, list2). When called with list arguments list1 and list2, it should return a new list dlist

Posted: Mon May 02, 2022 12:05 pm
by answerhappygod
Write A Function Diff List1 List2 When Called With List Arguments List1 And List2 It Should Return A New List Dlist 1
Write A Function Diff List1 List2 When Called With List Arguments List1 And List2 It Should Return A New List Dlist 1 (69.2 KiB) Viewed 43 times
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.