Перейти к содержанию

Lesson 48: Count every colour

English

Two lists, one index

  • Instead of three variables (red_count, green_count, blue_count), keep the counts in one list.
  • A second list holds the names. The same index joins them: index 0 is red in both.
  • Lists that go together like this are often called parallel arrays.
Index colours counts (map 1)
0 "red" 2
1 "green" 2
2 "blue" 3

Войти или создать аккаунт

IGCSE, A-Level & AP