0Pricing
Python Academy · Lesson

Modifying Lists

Append, insert, remove, and sort list elements.

Modifying Lists is a free Python Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Introduction

Lists are mutable — you can add, remove, and rearrange elements after creation.

append()

my_list.append(x) adds x to the end in O(1). It modifies the list in place and returns None.
lst = [1, 2]
lst.append(3)
print(lst)

insert()

my_list.insert(i, x) inserts x before index i. insert(0, x) prepends. O(n) due to shifting.
lst = [1, 3]
lst.insert(1, 2)
print(lst)

extend()

my_list.extend([4,5]) appends all elements of the iterable. Equivalent to my_list += [4,5].
lst = [1, 2]
lst.extend([3, 4])
print(lst)

remove()

my_list.remove(x) removes the first occurrence of x. Raises ValueError if x is not in the list.
lst = [1, 2, 3, 2]
lst.remove(2)
print(lst)

pop()

my_list.pop() removes and returns the last element. my_list.pop(0) removes the first. O(1) for end, O(n) for front.
lst = [1, 2, 3]
print(lst.pop())
print(lst)

del Statement

del my_list[1] removes element at index 1. del my_list[1:3] removes a slice.
lst = [1, 2, 3, 4]
del lst[1]
print(lst)

sort() and sorted()

lst.sort() sorts in place. sorted(lst) returns a new sorted list. Use key= for custom ordering.
lst = [3, 1, 4, 1, 5]
lst.sort()
print(lst)
print(sorted([3,1,2], reverse=True))

reverse()

lst.reverse() reverses in place. Returns None. To get a reversed copy use lst[::-1].
lst = [1, 2, 3]
lst.reverse()
print(lst)

count() and index()

lst.count(x) counts occurrences. lst.index(x) returns the first index — raises ValueError if absent.
lst = [1, 2, 2, 3]
print(lst.count(2))
print(lst.index(2))

clear()

lst.clear() removes all elements, leaving an empty list. Equivalent to del lst[:] but more readable.
lst = [1, 2, 3]
lst.clear()
print(lst)

Quick Check

Which method removes and returns the last element of a list?

Recap

Key list modifiers: append (end), insert (index), extend (iterable), remove (by value), pop (by index), sort, reverse, clear.

Keep Going

Great work! Move on to the next lesson to continue building your skills.

Frequently asked questions

Is the “Modifying Lists” lesson free?

Yes — the full text of “Modifying Lists” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.

What will I learn in “Modifying Lists”?

Append, insert, remove, and sort list elements. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Python Academy?

No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Modifying Lists” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Python Academy lesson?

Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Creating and Accessing Lists
  2. Modifying Lists
  3. Tuples and Immutability
  4. Nested Lists and Iteration
← Back to Python Academy