Data Structures Guide
A guide to data structures such as lists, dictionaries, 2D arrays, and iteration
games = ["Apex", "Fortnite", "Rocket League"]
games.append("PubG")
print(games)
games.remove("PubG")
print(games)
games = ["Apex", "Fortnite", "Rocket League"]
games.insert(1,"Clash Royale")
print(games)
games[1] = "Brawl Stars"
print(games)
games = ["Apex", "Fortnite", "Rocket League"]
games.pop(1)
print(games)
games.clear()
print(games)
Popcorn hack (0.3)
- Make a list related to your CPT project
- Make a while loop that will print each term in the list
- Make a for loop that will print each term in the list
Simulation mechanics
- In Python, pop() is a method that is used to remove and return an element from a list. The syntax for using pop() is as follows:
colors = ["red", "green", "blue", "purple", "orange"]
def whileLoop():
print("WHILE LOOP:\n")
# i is the iteration variable
# num is regarding the index
i = 0
num = 0
# While loop
while i<5:
i = i +1
# printing color of specified index
print(colors[num])
# adding to go down index
num = num +1
whileLoop()
print("")
print("")
def forLoop():
print("FOR LOOP:\n")
# for each color in the list, print
for x in colors:
print(x)
forLoop()