Read an item by its position
Pick an item using its position in the list. Here we read the second item every time.
List.__getitem__
Simple example
Read the second number.
Start4 · 7 · 9
Result7
def main() raises:
var values: List[Int] = [4, 7, 9]
print(values[1])
7
Advertisements
Everyday examples
Which ticket is second in the queue?
Start42 · 17 · 23
Result17
def main() raises:
var values: List[Int] = [42, 17, 23]
print(values[1])
17
Which stop does the bus visit second?
Start8 · 6 · 2
Result6
def main() raises:
var values: List[Int] = [8, 6, 2]
print(values[1])
6
What was the second thermometer reading?
Start19 · 21 · 20
Result21
def main() raises:
var values: List[Int] = [19, 21, 20]
print(values[1])
21