AP Computer Science Principles Flashcards: Lists

Study Lists in AP Computer Science Principles with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science Principles

Lists

0 mastered0 still learning

0% Complete

QUESTION
1/ 78

How do you convert a string to a list of characters?

Tap card or press Space to flip

ANSWER

list(string). Converts each character into a separate list element.

How well did you know it?

Card 1 / 78

What this deck covers

This deck focuses on Lists, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science Principles.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: How do you convert a string to a list of characters?

Answer: list(string). Converts each character into a separate list element.

Flashcard 2: What is the result of list.count(x)?

Answer: The number of times xx appears in the list. Returns frequency of occurrence for the specified element.

Flashcard 3: Which method returns the smallest item in a list?

Answer: min(list). Built-in function that finds the smallest comparable element.

Flashcard 4: What operation does list.clear() perform?

Answer: Removes all elements from the list. Empties the list completely, leaving it with zero elements.

Flashcard 5: How do you reverse a list in place?

Answer: list.reverse(). Reverses elements in-place without creating a new list.

Flashcard 6: Identify the syntax: [x for x in list if x > 0]

Answer: List comprehension filtering positive elements. Combines iteration with conditional filtering in one expression.

Flashcard 7: How do you create an empty list in Python?

Answer: list = []. Creates an empty list using square bracket notation.

Flashcard 8: What does list.extend(iterable) do?

Answer: Adds elements from the iterable to the end of the list. Extends the list with multiple elements from another collection.

Flashcard 9: Which method removes an element by value in a list?

Answer: list.remove(value). Removes the first matching value from the list.

Flashcard 10: What does list.copy() return?

Answer: A shallow copy of the list. Creates a new list object with the same elements.

Flashcard 11: Which method removes an element by value in a list?

Answer: list.remove(value). Removes the first matching value from the list.

Flashcard 12: Identify the operation: list.append(x)

Answer: Adds element xx to the end of the list. Appends to the end, increasing list length by 1.

Flashcard 13: What does list comprehension [x**2 for x in list] produce?

Answer: A list of squares of elements. Applies exponentiation operation to each list element.

Flashcard 14: Identify the method to concatenate two lists.

Answer: list1 + list2. Plus operator combines lists into a new list object.

Flashcard 15: What does list.sort() do?

Answer: Sorts the list in ascending order. Modifies the original list in-place using default ascending order.

Flashcard 16: Identify the operation: list.insert(index, x)

Answer: Inserts element xx at the specified index. Places element at specific position, shifting others right.

Flashcard 17: What is the result of list[::-1]?

Answer: The list in reverse order. Negative step creates a reversed copy of the list.

Flashcard 18: How do you iterate over a list with a for loop?

Answer: for element in list:. Iterates through each element without using indices.

Flashcard 19: How do you join a list of strings into a single string?

Answer: 'separator'.join(list). Combines string elements with specified separator between them.

Flashcard 20: What does list.index(x) return?

Answer: The index of the first occurrence of xx in the list. Returns position of first match; raises ValueError if not found.

Flashcard 21: What does list.sort() do?

Answer: Sorts the list in ascending order. Modifies the original list in-place using default ascending order.

Flashcard 22: What is a nested list?

Answer: A list that contains other lists as elements. Enables creation of multi-dimensional data structures.

Flashcard 23: How do you reverse a list in place?

Answer: list.reverse(). Reverses elements in-place without creating a new list.

Flashcard 24: What does 'in' keyword check in lists?

Answer: Checks if an element exists in the list. Returns True if element found, False otherwise.

Flashcard 25: What does list[start:end] return?

Answer: A sublist from index start to end-1. End index is exclusive, so it's not included in result.

Flashcard 26: What does list.copy() return?

Answer: A shallow copy of the list. Creates a new list object with the same elements.

Flashcard 27: Identify the operation: list.append(x)

Answer: Adds element xx to the end of the list. Appends to the end, increasing list length by 1.

Flashcard 28: What is the complexity of list.append(x)?

Answer: O(1). Constant time since it adds to the end only.

Flashcard 29: What is the default step in list slicing?

Answer:

  1. When no step specified, moves one position at a time.

Flashcard 30: What is the result of len(list)?

Answer: The number of elements in the list. Built-in function that counts all elements in the list.

Flashcard 31: Identify the method to concatenate two lists.

Answer: list1 + list2. Plus operator combines lists into a new list object.

Flashcard 32: How do you access the last element of a list?

Answer: list[-1]. Negative indexing starts from the end of the list.

Flashcard 33: What does list.extend(iterable) do?

Answer: Adds elements from the iterable to the end of the list. Extends the list with multiple elements from another collection.

Flashcard 34: How do you check list equality in Python?

Answer: Using the '==' operator. Compares element by element for both content and order.

Flashcard 35: What is the index of the first element in a list?

Answer:

  1. Lists use zero-based indexing in most programming languages.

Flashcard 36: Identify the operation: list.insert(index, x)

Answer: Inserts element xx at the specified index. Places element at specific position, shifting others right.

Flashcard 37: What is the complexity of list.append(x)?

Answer: O(1). Constant time since it adds to the end only.

Flashcard 38: What is the purpose of a list index?

Answer: To access a specific element in the list by its position. Indices provide direct access to elements without iteration.

Flashcard 39: What is slicing in the context of lists?

Answer: Extracting a portion of the list using indices. Creates sublists using start and end index boundaries.

Flashcard 40: What type of data structure is a list in Python?

Answer: Mutable, ordered collection. Lists can be modified after creation and maintain element order.

Flashcard 41: Which method returns the largest item in a list?

Answer: max(list). Built-in function that finds the largest comparable element.

Flashcard 42: What is slicing in the context of lists?

Answer: Extracting a portion of the list using indices. Creates sublists using start and end index boundaries.

Flashcard 43: What is the result of list.count(x)?

Answer: The number of times xx appears in the list. Returns frequency of occurrence for the specified element.

Flashcard 44: Which method removes an element by index in a list?

Answer: list.pop(index). Removes and returns the element at the specified position.

Flashcard 45: What is the default step in list slicing?

Answer:

  1. When no step specified, moves one position at a time.

Flashcard 46: What does list.index(x) return?

Answer: The index of the first occurrence of xx in the list. Returns position of first match; raises ValueError if not found.

Flashcard 47: Identify the syntax: [x for x in list if x > 0]

Answer: List comprehension filtering positive elements. Combines iteration with conditional filtering in one expression.

Flashcard 48: What does 'in' keyword check in lists?

Answer: Checks if an element exists in the list. Returns True if element found, False otherwise.

Flashcard 49: What does list[start:end] return?

Answer: A sublist from index start to end-1. End index is exclusive, so it's not included in result.

Flashcard 50: How do you access the last element of a list?

Answer: list[-1]. Negative indexing starts from the end of the list.

Flashcard 51: How do you create an empty list in Python?

Answer: list = []. Creates an empty list using square bracket notation.

Flashcard 52: Which function returns the sum of elements in a list?

Answer: sum(list). Built-in function that adds all numeric elements together.

Flashcard 53: Which function returns the sum of elements in a list?

Answer: sum(list). Built-in function that adds all numeric elements together.

Flashcard 54: What is a nested list?

Answer: A list that contains other lists as elements. Enables creation of multi-dimensional data structures.

Flashcard 55: What type of data structure is a list in Python?

Answer: Mutable, ordered collection. Lists can be modified after creation and maintain element order.

Flashcard 56: How do you join a list of strings into a single string?

Answer: 'separator'.join(list). Combines string elements with specified separator between them.

Flashcard 57: Which method returns the largest item in a list?

Answer: max(list). Built-in function that finds the largest comparable element.

Flashcard 58: What is the purpose of a list index?

Answer: To access a specific element in the list by its position. Indices provide direct access to elements without iteration.

Flashcard 59: How do you check list equality in Python?

Answer: Using the '==' operator. Compares element by element for both content and order.

Flashcard 60: Identify error: list.pop(-1) on empty list.

Answer: IndexError: pop from empty list. Cannot remove elements from a list with no elements.

Flashcard 61: What is the complexity of list.pop()?

Answer: O(1) for last element, O(n) for others. Last element removal is instant; others require shifting.

Flashcard 62: Find the error: list[1] = 100 on list of length 1.

Answer: IndexError: list index out of range. Index 1 doesn't exist in a list with only one element.

Flashcard 63: Which method returns the smallest item in a list?

Answer: min(list). Built-in function that finds the smallest comparable element.

Flashcard 64: What is the result of len(list)?

Answer: The number of elements in the list. Built-in function that counts all elements in the list.

Flashcard 65: Which method removes an element by index in a list?

Answer: list.pop(index). Removes and returns the element at the specified position.

Flashcard 66: What is the complexity of list.pop()?

Answer: O(1) for last element, O(n) for others. Last element removal is instant; others require shifting.

Flashcard 67: What is a list comprehension?

Answer: A concise way to create lists. Enables functional programming style for list creation.

Flashcard 68: What is the index of the first element in a list?

Answer:

  1. Lists use zero-based indexing in most programming languages.

Flashcard 69: What does list comprehension [x**2 for x in list] produce?

Answer: A list of squares of elements. Applies exponentiation operation to each list element.

Flashcard 70: How do you iterate over a list with a for loop?

Answer: for element in list:. Iterates through each element without using indices.

Flashcard 71: How do you convert a string to a list of characters?

Answer: list(string). Converts each character into a separate list element.

Flashcard 72: Find the error: list[1] = 100 on list of length 1.

Answer: IndexError: list index out of range. Index 1 doesn't exist in a list with only one element.

Flashcard 73: What is the result of list[::-1]?

Answer: The list in reverse order. Negative step creates a reversed copy of the list.

Flashcard 74: What is a list comprehension?

Answer: A concise way to create lists. Enables functional programming style for list creation.

Flashcard 75: What is a list in computer science?

Answer: A collection of elements, typically of the same type, in a specific order. An ordered data structure that allows indexing and modification.

Flashcard 76: Identify error: list.pop(-1) on empty list.

Answer: IndexError: pop from empty list. Cannot remove elements from a list with no elements.

Flashcard 77: What is a list in computer science?

Answer: A collection of elements, typically of the same type, in a specific order. An ordered data structure that allows indexing and modification.

Flashcard 78: What operation does list.clear() perform?

Answer: Removes all elements from the list. Empties the list completely, leaving it with zero elements.