GCGrowCarrer

Lists

Locked

Lesson 7 of 60 · DataStructures · Easy

LoopsNext: Tuples and Sets

Finish these first:Loops →Or pass the tests below to unlock it now.

1

The big idea

Lists are ordered, mutable sequences. Beware aliasing: b = a makes both names point to the same list; use a.copy() or a[:].

Think of it like this: Think of data structures as specialized toolboxes: a List keeps items in numbered slots (`0, 1, 2...`), a Set keeps only unique badges, and a Dictionary/Map labels each compartment with a custom name key.
Key words (tap to learn):
2

Read the lesson

Lists are ordered, mutable sequences.

xs = [3, 1, 2]
xs.append(4); xs.pop(); xs.sort()
xs[0], xs[-1], xs[1:]
len(xs), 2 in xs

Beware aliasing: b = a makes both names point to the same list; use a.copy() or a[:].

3

Quick check

Before writing code: What should `second_largest([1,3,2])` return when your implementation of Lists is working?

4

Your challenge

2 sample tests, 1 hidden

Write second_largest(xs) returning the second largest distinct value.

Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)

Compare with another language

Similar to javascript.arrays-lists (86% overlap). Dynamic contiguous arrays: Array in JS, std::vector in C++, slices []T in Go, Vec<T> in Rust.

Visual walkthrough

A diagram, a step-by-step animation, and short captions for Lists.

Mastery0%