Question

Python: Write a function symmetricDiff that has two parameters of type set and returns a new...

Python:

  1. Write a function symmetricDiff that has two parameters of type set and returns a new set that is of all the items in one set but not the other. Note: This is very similar but not quite the same as what the .difference() method returns (if you use that method carefully, this problem can be very short indeed).
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def symmetricDiff(set1, set2):
    result = []
    for x in set1:
        if not(x in set2):
            result.append(x)
    for x in set2:
        if not(x in set1):
            result.append(x)
    return set(result)

# Testing
set1 = set([4,2,0,7,9])
set2 = set([1,2,8,6,9])
print(symmetricDiff(set1,set2))

Add a comment
Know the answer?
Add Answer to:
Python: Write a function symmetricDiff that has two parameters of type set and returns a new...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT