7.6.1 Extending Data Structures Quiz, APCSP Basic Data Structures Quiz

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/23

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

24 Terms

1
New cards

Given the following list,

my_list = [

[0, 1, 2],

[3, 4, 5],

[6, 7, 8],

[9, 10, 11]

]

what will be printed when the following line of code is called?

print(my_list[3][1:])

[10, 11]

2
New cards

Given the following list,

my_list = [

[0, 1, 2],

[3, 4, 5],

[6, 7, 8],

[9, 10, 11]

]

Which line of code would print the number '5' to the screen?

print(my_list[1])

print(my_list[1:2])

print(my_list[1][2])

print(my_list[2][3])

print(my_list[1][2])

3
New cards

What kind of data structure is user_data in the following declaration?

user_data = {"name": "TJ", "age":24, "user_name":"artLover123"}

Tuple

List

Dictionary

2D List

Dictionary

4
New cards

What is the output of this program?

dimensions = [

[12, 3, 5],

[45, 7, 8],

[1, 2, 3]

]

for row in dimensions:

for num in row:

print(num)

12

3

5

45

7

8

1

2

3

5
New cards

Which of the following code snippets will create this 2D list?

[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]

board = [1, 2, 3] + [4, 5, 6] + [7, 8, 9]

board = [1, 2, 3]

board.append([4, 5, 6])

board.append([7, 8, 9])

board = [1, 2, 3, 4, 5, 6, 7, 8, 9]

board = []

board.append([1, 2, 3])

board.append([4, 5, 6])

board.append([7, 8, 9])

board = []

board.append([1, 2, 3])

board.append([4, 5, 6])

board.append([7, 8, 9])

6
New cards

Which of the following list comprehensions will create the same list as the for loop below?

my_list = []

for i in range(6):

my_list.append(i*2)

my_list = [i for i in range(6)]

my_list = [i*2 for i in range(6)]

my_list = [i for i*2 in range(6)]

This cannot be done using a list comprehension statement.

my_list = [i*2 for i in range(6)]

7
New cards

What does "packing" refer to in Python?

Storing multiple variables' values by putting them in a collection, like a list or tuple

8
New cards

What does "unpacking" refer to in Python

Initializing multiple variables at a time using a collection of values

9
New cards

Which of the following assignment statements is equivalent to the following code snippet?

coffee, tea, smoothie = ["kona", "mango", "raspberry"]

coffee = "kona"

tea = "mango"

smoothie = "raspberry"

coffee = "raspberry"

tea = "mango"

smoothie = "kona"

coffee = "kona"

tea = "kona"

smoothie = "kona"

coffee = ["kona", "mango", "raspberry"]

tea = ["kona", "mango", "raspberry"]

smoothie = ["kona", "mango", "raspberry"]

coffee = "kona"

tea = "mango"

smoothie = "raspberry"

10
New cards

Which of the following assignment statements is equivalent to the following code snippet?

red, blue, green = "BLUE", "GREEN", "RED"

red = "RED"

blue = "BLUE"

green = "GREEN"

red = "BLUE"

blue = "GREEN"

green = "RED"

red = ["BLUE", "GREEN", "RED"]

blue = ["BLUE", "GREEN", "RED"]

green = ["BLUE", "GREEN", "RED"]

red = "BLUE"

blue = "BLUE"

green = "BLUE"

red = "BLUE"

blue = "GREEN"

green = "RED"

11
New cards

A dictionary maps:

keys to values

12
New cards

What is the output of this program?

plants = {

"tree" : "oak",

"flower" : "daisy",

"weed" : "bindweed"

}

for plant in plants:

print(plants[plant])

oak

daisy

bindweed

13
New cards

Use the following definitions of foods and groceries.

foods = ["apples", "eel", "kale"]

groceries = ["apples", "eel", "kale"]

Which of the following statements would evaluate to True about foods and groceries?

I. foods == groceries

II. foods is groceries

I only

14
New cards

Given the following list,

my_list = [

[0, 1, 2],

[3, 4, 5],

[6, 7, 8],

[9, 10, 11]

]

which line of code will print the following output?

[[3, 4, 5], [6, 7, 8]]

print(my_list[1:3])

print(my_list[1:2])

print(my_list[2:3])

print(my_list[2:4])

print(my_list[1:3])

15
New cards

In the following array:

var groceries = ["milk", "eggs", "cookies", "cake"];

Which of the following statements will change "cookies" to "bread"?

C:

groceries[2] = "bread";

16
New cards

What is the output of the following program?

var arr = [1, 2, 3, 4, 5]; var removed = arr.remove(2); println(arr); println(removed);

D:

[1, 2, 4, 5]

3

17
New cards

Suppose we have a list groceryList shown below:

var groceryList = ["milk", "bread", "eggs", "sugar", "carrots", "apples"];

We want to write a function addGrocery that will take a grocery list and an item as a parameter and add the item on to the end of the grocery list. For example

println(groceryList); addGrocery(groceryList, "potatoes"); println(groceryList);

Should print out

["milk", "bread", "eggs", "sugar", "carrots", "apples"] ["milk", "bread", "eggs", "sugar", "carrots", "apples", "potatoes"]

Which of the following is the correct implementation of addGrocery?

C:

function addGrocery(groceryList, item){ groceryList.push(item);

}

18
New cards

Suppose we have a list groceryList shown below:

var groceryList = ["milk", "bread", "eggs", "sugar", "carrots", "apples"];

Once we buy a certain item, we should remove it from the list to show that we bought it. We want to write a function removeGrocery that will take an item as a parameter and remove it from our grocery list. For example

println(groceryList); removeGrocery(groceryList, "bread"); println(groceryList);

Should print out

["milk", "bread", "eggs", "sugar", "carrots", "apples"] ["milk", "eggs", "sugar", "carrots", "apples"]

Which of the following is the best implementation of removeGrocery?

C:

function removeGrocery(groceryList, item){ var index = groceryList.indexOf(item); if(index != -1){ groceryList.remove(index);

}

}

19
New cards

We want to be able to read our grocery list in a readable format while we're shopping. We decide to write a function printGroceries such that the following code:

var groceryList = ["milk", "bread", "eggs", "sugar", "carrots", "apples"]; printGroceries(groceryList);

Should print out

1. milk 2. bread 3. eggs 4. sugar 5. carrots 6. apples

printGroceries should not modify the groceryList array at all, the array should be in the same state after being printed as it was before it was printed. Which of the following is the best implementation of printGroceries?

C:

function printGroceries(groceryList){

for(var i = 0; i < groceryList.length; i++){ println((i + 1) + ". " + groceryList[i]);

}

20
New cards

What does the following function mystery do?

function mystery(list){

var result = []; while(list.length > 0){ var elem = list.pop(); result.push(elem);

}

return result;

}

B:

Returns a new list containing the elements of the list list in reverse order, and leaves list empty

21
New cards

What is an array (or list)?

B:

An ordered collection of items

22
New cards

A group of scientists has developed a simulation that simulates traffic in a city based on several factors. Which of the following statements is most likely something that can be learned from this simulation?

A:

Which roads are most likely to need maintenance in the near future

23
New cards

What is the output of the following program:

var groceries = ["bread", "bananas", "apples", "cheese", "peanuts"]; println(groceries.indexOf("bananas"));

B:

1

24
New cards

Which of the following statements are true about simulation models?

I - Models often omit unnecessary features of the phenomena being modeled.II - The time it takes for a simulation to run increases as the underlying model becomes more complex.

C:

I and II

Explore top flashcards