Creating Lists
Accessing an Element in a List
Lists and Expressions
Modifying Lists
100

Write the code to create an empty list named myList

myList = []

100

The following list has been been created:

lunchFood = ["nachos", "pizza", "soup"]

What is lunchFood[0]?

"nachos"

100

myNumbers = [10, 20, 25]

Evaluate the following expression:

5 * myNumbers[0]

50

100

myNumbers = [5, 10, 15, 20]

What does the list myNumbers contain after running the code below?

myNumbers.remove(10)

[5, 15, 20]

200

Write the code to create a list named breakfastFood that contains the strings "bacon", "eggs", and "cereal"

breakfastFood = ["bacon", "eggs", "cereal"]

200

The following list has been been created:

lunchFood = ["nachos", "pizza", "soup"]

What is lunchFood[len(lunchFood)-1]?

"soup"

200

myNumbers = [10, 20, 25]

Evaluate the following expression:

myNumbers[2] - myNumbers[1]

5

200

myNumbers = [5, 10, 15, 20]

What does the list myNumbers contain after running the code below?

del myNumbers[1]


[5, 15, 20]

300

Write the code to create a list named primeNumbers that contains the first five prime numbers

primeNumbers = [2, 3, 5, 7, 11]

300

The following list has been been created:

lunchFood = ["nachos", "pizza", "soup"]

What is lunchFood[len(lunchFood)]?

IndexError: list index out of range

300

myStuff = ["mouse","cheese",5,2]

myStuff[myStuff[3]] = myStuff[0]

myStuff[0] = "house"

What is contained in the list myStuff after this program has run?

["house","cheese",5,"mouse"]

300

myNumbers = [5, 10, 15, 20]

What does the list myNumbers contain after running the code below?

myNumbers.append(25)

myNumbers.insert(1,50)

[5, 50, 10, 15, 25]

400

A list named myNums has already been created and initialized with four values.

Write the code to create a new list named myNums2 that contains the same elements as myNums but in reversed order (ex: if myNums = [1,2,3,4] then myNums2 should equal [4,3,2,1])

myNums2 = [myNums[3], myNums[2], myNums[1], myNums[0]]

400

The following list has been created in code:

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

What is numbers[numbers[1]]?

2

400

nums = [3, 7, 15, 1]

nums[0] = nums[len(nums)-1]

nums[1] = nums[len(nums)-2]

What is contained in the list nums after this program has run?

[1, 15, 15, 1]

400

myNumbers = [5, 10, 15, 20]

What does the list myNumbers contain after running the code below?

del myNumbers[2]

myNumbers.append(myNumbers[2])

[5, 10, 20, 20]

500

Two lists have already been created in the code:

firstNames = ["John", "Marie", "Jia"]

and

lastNames = ["Martinez", "Lee", "Jones"]

Write the code to create a new list called names that contains the corresponding first name/ last name pairs. Ex: The first element should contain "John Martinez"

names = [firstNames[0] + " " + lastNames[0], firstNames[1] + " " + lastNames[1], + firstNames[2] + " " + lastNames[2]]

500

The following list has been created in code:

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

What is numbers[len(numbers)-numbers[len(numbers)-1]]?

1

500

nums = [3, 7, 15, 1]

temp = nums[0]

nums[0] = nums[len(nums)-1]

nums[len(nums)-1] = temp

temp = nums[1]

nums[1] = nums[len(nums)-2]

nums[len(nums)-2] = temp

What is contained in the list nums after this program has run?

[1, 15, 7, 3]

500

bList = ["to", 5, "po"]

bList.append(bList[2] + "ta" + bList[0]) 

bList.insert(2-1, "go")

bList.remove(5)

What does the list bList contain at the end of this program?

["to", "go", "po", "potato"]