+ 8
Why we use SET instead of using array?? , it says both are same but i feel set a little bit uncomfortable? is there any idea of using SET? I want to know some cool fact about using set?
4 Réponses
+ 12
Sets and Arrays are different data structures. While you can repeat elements in an Array the same is not valid for Sets. This assumption has consequences both for us developers and for the language architecture. If you iterate over a list that you know to have not a duplicate value, when you find the first occurrence you can stop your search and return the value index (or other information) that's how Sets works on the "Inside". Now to answer your question more precisely, if you require the values stored to be unique, use Sets, if not, use an Array
+ 4
I'm guessing, but it seems arrays are more for user input like fill in the blanks of a multi answer question, or reminder lists (like in the example). While sets are more for comparison purposes of participants or something nonadjustable from the participants perspective. Like when we look at the leaderboard in sololearn and you can check where you're at in this course vs all courses.
+ 2
no duplicates?
+ 2
Sets are great for unique value lists where you don't care to mange an index.