0

# Python: set&set process?

Hi, Came across a question in challenge: a=set([1,2,3,4]) b=set([1,2,5,6]) x=a&b print(x) print(len(x)) Why is the outcome as below? {1, 2} 2 Interestingly, trying out different method a=set([1,2,3,4]) b=set([4,3,2,1]) x=a&b print(x) print(len(x)) ------outcome----------- {1, 2, 3, 4} 4

2 Answers

+ 7

set & other & ...
Return a new set with elements common to the set and all others.
https://docs.python.org/3/library/stdtypes.html#set

+ 2

Take a look at the third slide of this lesson:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2464/