0

Why repeated number are not printed in set? Does same thing happens in dictionary? nums = {1, 2, 1, 3, 1, 4, 5, 6} print(nums)

nums = {1, 2, 1, 3, 1, 4, 5, 6} print(nums)

2nd Jul 2021, 9:06 AM
Zahed Shaikh
Zahed Shaikh - avatar
5 Answers
+ 6
this is what makes a set: no dups.
2nd Jul 2021, 9:20 AM
Oma Falk
Oma Falk - avatar
+ 5
in dicts keys are unique. last one wins.
2nd Jul 2021, 9:20 AM
Oma Falk
Oma Falk - avatar
+ 2
Zahed Shaikh It's very simple sets doens't allow duplicate values.
2nd Jul 2021, 10:00 AM
A͢J
A͢J - avatar
+ 1
I assume that the programmers who implemented the set had a condition that checks if the given value already exists in the set. If it exists- the given number won't be added..
2nd Jul 2021, 9:20 AM
Yahel
Yahel - avatar
+ 1
+ 2 Cents to all above mentioned things: sets are not ordered. i.e.: they will appear randomly every time.
2nd Jul 2021, 1:50 PM
Shadoff
Shadoff - avatar