typestar

List methods in Python

The mutating operations every Python list supports.

stack = [3, 1, 4]

stack.append(1)
stack.insert(0, 5)
top = stack.pop()
stack.remove(1)

stack.sort()
stack.reverse()
where = stack.index(4)
count = stack.count(3)
stack.extend([9, 2])

How it works

  1. append, insert, and pop change the ends.
  2. remove deletes by value; index finds one.
  3. sort and reverse reorder in place.

The run, in numbers

Lines
12
Characters to type
184
Tokens
72
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 48 seconds.

Type this snippet

Step 3 of 10 in Collections, step 25 of 72 in Language basics.

← Previous Next →