Basic set operation. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Basic set operation.

x = {1,2,3} y ={2,3,4}. How could you get { 4} from x and y using basic set operation

16th Apr 2020, 9:29 AM
Kriti Parashar
3 Answers
+ 5
print( y - x & y ) x & y will give common elements among them so {2 , 3} now y -{2, 3} will remove the element {2, 3} from y so {4} is all that is left Edit: print( y - x ) will also work as answered by HonFu
16th Apr 2020, 9:34 AM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 4
HonFu Oh! Totally forgot about that.
16th Apr 2020, 9:52 AM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 3
y-x
16th Apr 2020, 9:51 AM
HonFu
HonFu - avatar