0
im stuck at this "SET" coding problem
You are working on a recruitment platform, which should match the available jobs and the candidates based on their skills. The skills required for the job, and the candidate's skills are stored in sets. Complete the program to output the matched skill. My code skills = {'Python', 'HTML', 'SQL', 'C++', 'Java', 'Scala'} job_skills = {'HTML', 'CSS', 'JS', 'C#', 'NodeJS'} print(skills & job_skills) why it doesnt work?
2 Réponses
+ 3
jack bridgwater
Your idea is correct. But the coding problem expects a very specific output ~
HTML
The common way around this is to convert the set intersection to a list and take the first item ~
s = skills & job_skills
print(s) # {'HTML'}
print(list(s)) # ['HTML']
print(list(s)[0]) # HTML
Another way is to use the * operator to unpack the set item directly into print() ~
print(*(skills & job_skills)) # HTML
IMO, the problem statement should have been clearer about the expected output. If in the future, you find yourself struggling with a lesson problem, do check out the comment section. Plenty of helpful info there :)
+ 1
I don't think we need a pair of additional parenthesis, just use :
...
print(*skills & job_skills)
It works like this:
skills & job_skill is executed first, then the unpack operator takes the result and print will output it. the output is:
HTML