A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

List Operations and Methods

College Depth 76 in the knowledge graph I know this Set as goal
529topics build on this
331prerequisites beneath it
See this on the map →
Arrays and ListsString Operations and MethodsAlgorithm Design BasicsList Comprehensions
lists append remove sort slicing searching

Core Idea

Lists expose methods for in-place modification: append() adds to the end, insert() adds at a position, remove() deletes by value, and pop() removes by index. Sorting (sort() for in-place, sorted() for a new list) reorders elements. Slicing copies a portion of a list. Membership testing with in searches linearly. Understanding whether an operation modifies the list in place or returns a new one is critical for avoiding subtle bugs.

How It's Best Learned

Write programs that build sorted frequency tables: read words, append to a list, sort, and count duplicates. Experiment with sort vs. sorted, and pop vs. remove, to feel their differences.

Common Misconceptions

Explainer

You already know that lists are ordered, mutable collections that can hold multiple values. Now it's time to learn what you can *do* with them. List operations fall into a few categories: adding elements, removing elements, searching for elements, reordering elements, and extracting portions of a list. Each operation either modifies the list in place or returns a new value — and knowing which one does which is the key to avoiding subtle bugs.

Adding elements is straightforward. `append(value)` adds an item to the end of the list — it's the most common way to grow a list one element at a time. `insert(index, value)` lets you place an element at a specific position, shifting everything after it one position to the right. If you're building up a list of results in a loop, `append` is your go-to. For example, collecting all even numbers from a range: start with an empty list, loop through the range, and `append` each even number. This pattern — initialize, loop, append — is fundamental and shows up constantly in real programs.

Removing elements requires care because there are two different approaches. `remove(value)` searches for the first occurrence of a value and deletes it — if you have `[3, 1, 4, 1]` and call `remove(1)`, you get `[3, 4, 1]` (only the first 1 is removed). `pop(index)` removes the element at a given position and returns it, which is useful when you need the removed value. Called with no argument, `pop()` removes the last element — handy for using a list as a stack. The distinction matters: `remove` finds by value, `pop` finds by position. Using the wrong one is a common source of confusion, especially with lists of integers where a value might look like an index.

Sorting and slicing round out the essential operations. `sort()` reorders a list in place and returns `None` — this is the detail that trips up most beginners. Writing `my_list = my_list.sort()` destroys your reference to the sorted list because `sort()` returns `None`, not the sorted list. If you need a sorted copy without modifying the original, use the built-in function `sorted()`, which returns a new list. Slicing with the syntax `list[start:stop]` extracts a portion of the list as a new list, from `start` up to but not including `stop`. Like string slicing you may have seen, it supports negative indices (counting from the end) and a step parameter (`list[::2]` gives every other element). Slicing never modifies the original list — it always produces a copy. Finally, the `in` operator tests membership: `5 in my_list` returns `True` if 5 appears anywhere in the list, performing a linear search from beginning to end.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraConditional StatementsWhile LoopsFor LoopsArrays and ListsList Operations and Methods

Longest path: 77 steps · 331 total prerequisite topics

Prerequisites (2)

Leads To (2)