This is the first of two videos where I go over the basics of how to work with "Sets" in Python. I am not an expert when it comes to Python, but I know that teaching a subject helps solidify the information learned about.
This is Series A
Series A = 1
Series B = 2
Each series is intended to be better than the last because of all the practice I'll get in creating them.
✔ Other Places to Connect:
My Website: https://dougm.io/
✔ Support Through Patreon:
https://www.patreon.com/user?u=322207...
✔Learn More about Python Sets at - w3schools
https://www.w3schools.com/python/pyth...
✔Additional Practice Questions
https://github.com/MorrowG2/YouTube_P...
✔Practice Questions
https://github.com/MorrowG2/YouTube_P...
Sets
An unordered pair of UNIQUE objects
my_set = {1,2,3,4,5,5}
print(my_set.add(480))
print(my_set.add(410))
print(my_set.add(420))
print(my_set.add(450))
print(my_set)
set2 = my_set.copy()
print("-"*40)
set2.add(500)
print(set2)
print("-"*40)
new_variable = my_set.clear()
print(new_variable)
print("-"*40)
print(my_set)
print("-"*40)
my_set.add(500)
print(my_set)
print("-"*40)
my_list = [1,2,3,4,5,5]
print(set(my_list))
No Key Value Pairs, just values
.add()
set() - useful when considering "primary keys" - username - email - ssn
index = [] VS "in" keyword -- link in the discription that there are addiontal keywords
len()
list() w/ a new variable
.copy() and .clear()
---------------------------------------------------------------------------------------------------
1. What do Sets do in Python? They return ... (answer here)
2. This open ended question) Can you think of ways to use a Set in your own algorithm?
---------------------------------------------------------------------------------------------------------------
3. How can you add an item to a Set?
4. Create 2-5 Sets with different variables
Example:
my_set = {1, 2, 3, 4, 5, 5, 6, 8, 9, 10, 11, 5, 4, 8}
my_set2 = {}
---------------------------------------------------------------------------------------------------------------
Can use strings, integers, and boolean values in a Set?
Test the above by adding 2-8 string values to your Set. What about a boolean? Can you add a boolean to your Set? (Booleans are True/False)
Bit of a trick question below.
5. What happens when you print(my_set2.add(33)) and why is the output returned? Is an action taken? Is a value returned?
If you get an error why do you think that it?
# 6. Is a value returned when your print the below?
my_set3 = {1}
print(my_set3.add(33))
7. What action is performed when you print the above?
---------------------------------------------------------------------------------------------------------------
8. How can you turn my_set3 into a list?
9. What keyword can you use to identify if an object/value is in a Set?
10. In a List: Remember a List is - my_list = [1,2,3] - Can you use an index to identify a value in a Set?
AN index is - my_list[2]
Can you perform the above in a Set to identify a value?
---------------------------------------------------------------------------------------------------------------
11. For this task, return the length of the following Set
my_set4 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 'a', 'b', 'c', 's', 'e', 'i', "('_')", "(*-*)", ':P'}
12. How can you copy the above Set?
13. How can you clear the copy of the above Set?