asked 184k views
4 votes
Write a python function, (goDisplay), that will return the unique elements of myListOne and myListTwo.

myListOne = {1,2,3,4,5}
myListTwo = {4,5,6,7,8}

asked
User Alok P
by
8.3k points

1 Answer

3 votes

Answer:

Here’s a Python function that takes two lists as arguments and returns their unique elements:

def goDisplay(myListOne, myListTwo):

unique_elements = set(myListOne) ^ set(myListTwo)

return list(unique_elements)

myListOne = [1,2,3,4,5]

myListTwo = [4,5,6,7,8]

print(goDisplay(myListOne, myListTwo))

This function uses the ^ operator to find the symmetric difference between two sets. The symmetric difference of two sets is the set of elements that are in either of the sets but not in both. This will give us the unique elements from both lists. Finally we convert the resulting set back to a list and return it.

answered
User Baran
by
9.1k points