Sobes.tech
Junior — Senior

List with indexing starting from 1

livecode

Task condition

It is necessary to implement a class MathList that mimics a regular list but uses 1-based indexing instead of the usual 0-based. An instance of this class should support adding elements via the append method, as well as reading and modifying values by index, where the first element has index 1.

a = MathList()

a.append(1)
a.append(2)

assert a[1] == 1
assert a[2] == 2

a[2] = 3
assert a[2] == 3