0Pricing
Mojo Academy · Lesson

Building and Growing a List

Append, index, and iterate a List.

Building and Growing a List is a free Mojo Academy lesson on CoddyKit — lesson 1 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 Mojo Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why a List?

When you need an ordered, growable group of values, reach for a List. It holds items in sequence and can stretch as you add. 📋

A Typed Container

A Mojo List is typed: every element shares one type, like List[Int]. That uniformity is what makes it fast.

var nums = List[Int]()

Start Empty

Calling List[Int]() gives you an empty list ready to fill. The type in brackets says what it will store.

var scores = List[Int]()

Append an Item

Add a value to the end with append. Each call grows the list by one, keeping insertion order.

scores.append(90)
scores.append(85)

Read by Index

Reach an element with square brackets and its position. Indexing is zero-based, so the first item is at 0.

var first = scores[0]

How Many Items

Ask a list its size with len. It returns the current count, which changes as you append or remove.

var n = len(scores)

Change an Element

Assign through an index to replace a value in place. The list stays the same length; only that slot updates.

scores[0] = 100

Iterate the Items

Walk a list with a for loop. It hands you each element directly, so you rarely manage indices yourself.

for s in scores:
    print(s)

Build From a Literal

You can fill a list at creation with a list literal. Mojo infers the element type from the values you give.

var fruits = List[String]("apple", "pear")

Remove From the End

Drop the last item with pop. It shrinks the list and hands back the value you removed.

var last = scores.pop()

Lists Grow on the Heap

A list stores its elements on the heap, so it can resize freely as you append. That flexibility is its superpower.

Quick Check

You have an empty List[Int] and call append three times. What is len of the list afterward?

Recap

A List is an ordered, typed, growable container. Use append to add, brackets to index, and len to count. 🎯

Frequently asked questions

Is the “Building and Growing a List” lesson free?

Yes — the full text of “Building and Growing a List” is free to read here on the web, and the Mojo 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 Mojo Academy course, upgrade to CoddyKit PRO.

What will I learn in “Building and Growing a List”?

Append, index, and iterate a List. You practise Mojo 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 Mojo Academy?

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

How long does the “Building and Growing a List” 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 Mojo Academy lesson?

Yes. Every Mojo 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. Building and Growing a List
  2. Key-Value Data with Dict
  3. Unique Items with Set
  4. Choosing the Right Collection
← Back to Mojo Academy