+ 3
What's the difference between a set, a list and a tuple?
I don't seem to wrap my head around it any practice suggestion codes?
2 odpowiedzi
+ 5
set : don't allow dublicate values. created by curly braces { } or by set() function
s = { 1,2,3,4 } or set(1, 2,3,4)
array : a list of values, a list of lists. created by squire brackets [ ] or list() function
l = [ 1,2, 3, 4 ] , l = list(1, 2, 3, 4)
tuples : same as list but immutable means ones created, can't be changed.. created by paranthesis ( ) or by tuple() function
t = (1, 2, 3, 4) or tuple(1, 2, 3, 4)
+ 4
Sets are also unordered so none of the items are indexed
If you want to practice make a list with some values including duplicates.
Play around with some list methods (see W3schools if you want)
You can then covert your list to a set by doing set() around your list or use tuple() for tuple type and play around with methods and manipulating the data see what happens