0

Print the value not the Set

I want to print out the value of the union between two sets. But instead my code prints the Set itself. The desired output is: HTML not {'HTML'} https://code.sololearn.com/c2A9a21A3a7A

21st May 2021, 2:36 AM
Ellison
Ellison - avatar
4 odpowiedzi
+ 2
print(*(skills & job_skills))
21st May 2021, 2:40 AM
visph
visph - avatar
+ 2
skills = {'Python', 'HTML', 'SQL', 'C++', 'Java', 'Scala'} job_skills = {'HTML', 'CSS', 'JS', 'C#', 'NodeJS'} x = list(skills & job_skills) z = ' '.join(x) print(z)
21st May 2021, 4:31 AM
Shadoff
Shadoff - avatar
+ 1
I found this solution: skills = {'Python', 'HTML', 'SQL', 'C++', 'Java', 'Scala'} job_skills = {'HTML', 'CSS', 'JS', 'C#', 'NodeJS'} match = (skills & job_skills) for x in match: print(x) But I like the solution from @visph better. Thank you.
21st May 2021, 2:45 AM
Ellison
Ellison - avatar
+ 1
roughly, my solution does the same thing, but shorter: * here is the destructuring operator... it send all items of an iterable as arguments to the print() function, wich has the space as default separator ;)
21st May 2021, 2:48 AM
visph
visph - avatar