Indexing
Modifying Lists
Coding Lists
List Methods
Properties of Lists
100

fruits = ["Apple", "Banana", "Orange"]

What does fruits[1] give us?

"Banana"

100

names = []

names.append("Angel")

names.append("Emmanuel")

names.remove("Angel")

["Emmanuel"]

100

Make me a list of anything (with whatever length you want) and print out each item

Example response:

numbers = [1,2,3]

print(numbers[0])

print(numbers[1])

print(numbers[2])

100

colors = ["Red","Blue","Yellow"]

colors_2 = colors.copy()

print(colors_2)

["Red","Blue","Yellow"]

100

What does it mean for something to be mutable?

The ability to change the value of something (i.e. changing the value of a list)

200

fruits = ["Apple", "Banana", "Orange", "Strawberry"]

What does fruits[-3] give us?

"Banana"

200

names = ["Angel", "Emmanuel"]

names.insert(1, "Lydia")

names.pop(2)

["Angel, "Lydia"]

200

numbers = [1, 2, 3, 4, 5]

I want the number 5 to be first. Then, I want to remove the number 3. Finally, I want to add the number 6.

Final result: [5, 2, 4, 6]

Example response:

numbers.remove(5)

numbers[0] = 5

numbers.remove(3)

numbers.append(6)

200

colors = ["Red", "Red", "Red", "Red", "Blue"]

print(colors.count("Red"))

4

200
What can you store in a list? Give 4 examples.

Ints, floats, strings, lists, objects, functions, booleans, etc.

300

fruits = ["Apple", "Banana", "Orange", "Strawberry", "Grape", "Watermelon"]

What does fruits[6] give us?

Error: Index Out of Bounds
300

names = ["Angel", "Emmanuel", "Lydia"]

names.remove("angel")

Error!

300

numbers = [1, 2, 3, 4, 5, 6]

I want to check if the number 3 is in the list, and if it is then I want to remove it. Then, I want to add the number 7 if the number 2 is in the list

End result: [1, 2, 4, 5, 6, 7]

Example response:

if 3 in numbers:

     numbers.remove(3)

if 2 in numbers:

     numbers.append(7)


300

colors = ["Purple", "Red", "Green", "Lavender", "Violet"]

colors.reverse()

print(colors)

["Violet", "Lavender", "Green", "Red", "Purple"]

300

Why are we able to index into lists?

Lists are ordered

400

fruits = ["Apple", "Banana", "Orange", "Strawberry", "Grape", "Watermelon"]

What does fruits[:4] give us?

["Apple", "Banana", "Orange", "Strawberry"]

400

names = []

names.append(["Angel", "Emmanuel"])

names.insert(100, "Lydia")

[["Angel", "Emmanuel], "Lydia"]

400

numbers = [1, 2, 3, 4, 5]

I want to take user input, and if the user's number is in the list, remove it from the list

Example response:

user_number = int(input("Enter a number: "))

if user_number in numbers:

     numbers.remove(user_number)

400

colors = ["Blue", "Red", "Yellow", "Orange"]

colors.sort()

print(colors)

["Blue", "Orange", "Red", "Yellow"]

400

How many items can you put in a list?

An infinite amount!

500

fruits = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]

What does fruits[-4:-1] give us?

["orange", "kiwi", "melon"]
500

names = ["Angel", "Lydia", "Emmanuel"]

names[0:3] = "Angel"


['A','n','g','e','l']

500

30 SECONDS!!!

numbers = []

1. Add the numbers 1 through 4 to the list

2. Remove the number 3

3. Print out the number at index 3

4. Change the number in position 0 to 7

5. Reset the list to [1, 2, 3, 4] using appends and removes


This would produce an error! At step 3

500

colors = ["Pink", "Silver", "Gold"]

colors_2 = ["Scarlet", "Turquoise", "Gray"]

colors.extend(colors_2)

print(colors)

["Pink", "Silver", "Gold", "Scarlet", "Turquoise", "Gray"]

500

Explain 3 properties of lists

Mutable - can change the value of it

Ordered - can index into it (items are in a set order)

Dynamic - lists grow and shrink as needed

Can store any sorts of data (not code blocks like conditional statements)

Can be infinitely appended to