+ 2

Python output - Why is set(a) == b?

Code is: a = [1,2,3,2] b = {1,2,3,2} print(set(a)) print(set(a) == b)

7th Apr 2019, 6:42 AM
Paolo De Nictolis
Paolo De Nictolis - avatar
2 Answers
+ 3
Because b is a set. A set does not contain any duplicates. When defining b with curly braces, b is a set. a with Square brackets is a list. So set(a) is equal to b https://www.sololearn.com/Discuss/1733735/?ref=app
7th Apr 2019, 7:45 AM
Louis
Louis - avatar
+ 2
"a" - the list; "b" - set; a != b; the function "set" converts the list "a" to the set; set(a) == b; https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2464/
7th Apr 2019, 7:44 AM
Solo
Solo - avatar