Skip to content
CodeItRaw
Arrays

Lesson 1/6

Every element of a list has a position, and positions count from 0: the first is values[0], the second values[1]. A minus counts from the end: values[-1] is the last.

values = [10, 20, 30, 40, 50]
values[1:4] # [20, 30, 40]
values[:2] # [10, 20]
values[3:] # [40, 50]
A slice (a:b) gives a part of the list: a included, b not, just like range. An end left empty means "from the start" or "to the end".

A slice is not free: it builds a new list and copies every element in it. Take a slice inside a loop and that loop quietly becomes two nested loops.

Tasks

Tasks open in order. Solve them all and the next lesson opens.

  1. 01

    Slices

    Code reading · Predict the Output

  2. 02

    Peak Value

    Function

  3. 03

    Find the Largest

    Code reading · Bug Hunt

If you would rather not wait for the order, every problem is open without locks: Problem list