Why Sets?
00:00 So, why sets? Well, sometimes you only care about unique values/you donât want duplicates and you donât need your data structure to be ordered. Thatâs the obvious difference between sets and tuples or lists, is not ordered and no duplicates. You can also do some cool operations very easily.
00:19 We have union, symmetric difference, you can mutate using difference update or symmetric difference update or disjoint or superset or subset or proper superset or something like that. Where with lists and tuples, that might be a little harder to do.
00:34 But the main reason that we use setsâor, I shouldnât say the main reasonâa very important reason we use sets is that they are very, very fast. What I mean by that is you can check for membership almost instantly.
00:47 So, letâs actually see how sets compare with lists and tuples in terms of checking for membership.
Become a Member to join the conversation.
