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.

12th Jan 2022, 1:14 AM
shriram gharpure
4 Respuestas
+ 5
shriram gharpure , without having seen your code, we can only guess what the issue is.
12th Jan 2022, 3:14 PM
Lothar
Lothar - avatar
+ 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!
13th Jan 2022, 11:57 AM
Lothar
Lothar - avatar
0
skills = {'Python', 'HTML', 'SQL', 'C++', 'Java', 'Scala'} job_skills = {'HTML', 'CSS', 'JS', 'C#', 'NodeJS'} print(skills & job_skills)
12th Jan 2022, 11:07 PM
shriram gharpure