Intermediate Python : Exercise 6.2 (SETS) | Sololearn: Learn to code for FREE!


Intermediate Python : Exercise 6.2 (SETS)

I ran the code in it works. Cannot get the same result in the exercise. This is about using the & operator to find the intersection of 2 sets.

1/12/2022 1:14:49 AM

shriram gharpure

4 Answers

New Answer


shriram gharpure , without having seen your code, we can only guess what the issue is.


shriram gharpure , the output should be a *string*. unfortunately sololearn has removed the descriptions for input and output data in this exercise. the output of an operation with the "intersect operator" "&" is a set, so the output is: {'HTML'} to get this to a string, we can use the *splat* operator to *unpack* the element from the set: print(*(skills & job_skills)) we can also omit the additional pair of parenthesis in this case, but using the parenthesis is more obvious what we are going to achieve. happy coding!



skills = {'Python', 'HTML', 'SQL', 'C++', 'Java', 'Scala'} job_skills = {'HTML', 'CSS', 'JS', 'C#', 'NodeJS'} print(skills & job_skills)