1/16
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Dictionary
A dictionary is a collection of unordered, modifiable(mutable) paired (key: value) data type.
use it when you have a massive database and need to find a specific item instantly without checking every single one.
List
OPTIMIZED FOR ORDER, SEQUENCES, AND QUEUES
use it when the order of events matters and to keep track of a timeline (1st, 2nd, 3rd, etc.).
Tuple
A tuple is a collection of different data types which is ordered and unchangeable (immutable). Tuples are written with round brackets, (). Once a tuple is created, we cannot change its values. We cannot use add, insert, remove methods in a tuple because it is not modifiable (mutable). Unlike list, tuple has few methods. Methods related to tuples:
Set
a set is essentially a dictionary that only stores keys without associated values.
List Add
fruits.append('apple') # add
fruits.insert(1, 'grape') # Insert at index 1List Modify
fruits[0] = 'strawberry' # modifyList Access
first_item = fruits[0] # access
subset = fruits[1:3] # Slicing from index 1 up to 3
List Remove
fruits.remove('mango')
del fruits[0] # Removes item at index 0
popped_item = fruits.pop() # Removes and returns last itemDict Add
items["Iron Shield"] = {"type": "armor", "defense": 8, "price": 15} # add
Dict Modify
items["Rusty Sword"]["damage"] = 7 # modifyDict Access
sword_stats = items["Rusty Sword"] # access
damage = items["Rusty Sword"]["damage"] # 7
shield_stats = items.get("Iron Shield", "Not found")Dict Remove
del items["Rusty Sword"]["price"] # Deletes the nested 'price' key
removed_item = items.pop("Iron Shield") # Removes and returns the entry
Tuple Add
fruits = fruits + ('peach',) # addTuple Modify
temp_list = list(fruits) # modify
temp_list[0] = 'strawberry'
fruits = tuple(temp_list)Tuple Access
first_fruit = fruits[0] # access
middle_fruits = fruits[1:3] # ('orange', 'mango')Tuple Remove
fruits = fruits[1:] # Slices off the first element
del fruits # Deletes the entire variable reference