0
Intermediate Python : Exercise 6.2 (SETS)
I ran the code in repl.it it works. Cannot get the same result in the exercise. This is about using the & operator to find the intersection of 2 sets.
4 Antworten
+ 5
shriram gharpure ,
without having seen your code, we can only guess what the issue is.
+ 5
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!
0
skills = {'Python', 'HTML', 'SQL', 'C++', 'Java', 'Scala'}
job_skills = {'HTML', 'CSS', 'JS', 'C#', 'NodeJS'}
print(skills & job_skills)