+ 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?

25th Feb 2016, 11:38 AM
Madhab Dhakal
Madhab Dhakal - avatar
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
14th Jun 2016, 4:33 PM
Bruno Vieira
Bruno Vieira - avatar
+ 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.
11th Mar 2016, 9:50 PM
Heather Brown
Heather Brown - avatar
+ 2
no duplicates?
5th Mar 2016, 4:14 AM
Juan Rivera
Juan Rivera - avatar
+ 2
Sets are great for unique value lists where you don't care to mange an index.
12th Sep 2016, 8:57 PM
Alex