Fall 2024 - P2
Big Idea 3 | .1 | .2 | .3 | .4 | .5 | .6 | .7 | .8 | .10 |
3.2 Lesson Period 2 - Sets Data Abstraction
Student led teaching on Abstraction. Teaching how various data types can use abstraction for copmutational efficiency.
Sets - 3.2.7
##Unordered, unchanged, indexed, no duplicate values
myset = {"apple", "banana", "cherry"}
# Sets are abstractions because they provide an unordered collection of unique elements, without exposing the underlying mechanisms
print("\nThe whole set is:")
print(myset)
print("\nThe value of the index 0 is:")
for i in myset:
print(i)
print("\nTo add an orange:")
myset.add("orange")
for i in myset:
print(i)
print("\nTo remove a banana:")
myset.remove("banana")
for i in myset:
print(i)
The whole set is:
{'banana', 'apple', 'cherry'}
The value of the index 0 is:
banana
apple
cherry
To add an orange:
banana
orange
apple
cherry
To remove a banana:
orange
apple
cherry
Javascript
var myset = new Set(["apple", "banana", "cherry"]);
console.log(Array.from(myset).join(", "))
console.log(Array.from(myset).join(", "))
myset.add("orange");
console.log(Array.from(myset).join(", "))
myset.delete("banana");
console.log(Array.from(myset).join(", "))
Cell In[1], line 1
var myset = new Set(["apple", "banana", "cherry"]);
^
SyntaxError: invalid syntax