Lesson 7 of 12
Keep many values in one list, go through every item with For Each, and add, change or remove items. Learn arrays with flowchart blocks you can run.
About 7 minutes · 4 parts, each with a program to try
Part 1 of 4
A list holds many values in order: ["apple", "banana", "mango"]. Programmers also call it an array.
fruits[1] is the first item, and length(fruits) counts them.
fruits = ["apple", "banana", "mango"]"First: " + fruits[1]"How many: " + length(fruits)First: appleHow many: 3fruits = ["apple", "banana", "mango"]print("First: " + fruits[0])print("How many: " + str(len(fruits)))Part 2 of 4
For Each runs its body once for every item, with the item in a value of its own, like fruit.
fruits = ["apple", "banana", "mango"]fruit in fruitsRepeat →
"I like " + fruitback to the top for the next lap
I like appleI like bananaI like mangofruits = ["apple", "banana", "mango"]for fruit in fruits: print("I like " + fruit)Part 3 of 4
Change a List adds an item to the end, changes the item at a position, or removes one.
join(cart, ", ") turns a list into one line of text.
cart = []"pen" to the end of cart"book" to the end of cart1 of cart to "pencil"join(cart, ", ")pencil, bookcart = []cart.append("pen")cart.append("book")cart[0] = "pencil"print(", ".join(cart))Part 4 of 4
Go through a list and keep the best so far: a pattern for highest, lowest and totals.
marks = [45, 82, 67]best = 0mark in marksRepeat →
mark > best true?Yes →
best to markNo →
nothing, just carry on
back to the top for the next lap
"Top mark: " + bestTop mark: 82marks = [45, 82, 67]best = 0for mark in marks: if mark > best: best = markprint("Top mark: " + str(best))Quick check