| English | 意味 |
|---|---|
| list/lɪst/ | リスト |
| elements/ˈelɪmənts/ | 要素 |
| ordered collection/ˈɔːdəd kəˈlekʃn/ | 順序付き集合 |
| index/ˈɪndeks/ | インデックス |
| traverse/trəˈvɜːs/ | 反復 |
| general/ˈdʒenərəl/ | 汎用的 |
| append/əˈpend/ | 追加 |
A list holds many elements
- A list 列表 stores an ordered collection 有序集合 of values, called elements 元素, under one name.
- A single list
coloursmight hold "red", "green", and "blue". - One name replaces many separate variables.
- The order is fixed, so each element has a definite position.
リストが格納するのは:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
多数の値、1つの名前、固定された順序。
Access by index
- You access or change an element using its index 索引 — its position in the list.
- In many languages the first element is at index $0$:
colours[0]is "red". - Read
colours[1]to get "green", or assign tocolours[2]to change it. - Always check where a language starts counting.
要素にアクセスするか、リストを変更するか?
reading colours[1] は要素にアクセスします;append, insert, remove はリストの内容を変更します。
リストのインデックスが0から始まる場合、["red","green","blue"] の colours[0] は:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
インデックス0は最初の要素 "red" です。
ループを使ってリストのすべての要素を順に訪れることを______という。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
トラバースはリストのサイズに関わらず、リスト全体を処理する。
Traverse with a loop
- To process a whole list, use iteration to traverse 遍历 it.
- A loop visits every element in turn — first, second, third, and so on.
- The same loop works no matter how many elements the list holds.
- This is what makes list code so general 通用.
append操作は:
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
appendはリストの末尾に1つ増やす。
[70, 85, 90]をトラバースして各値を合計に加えると、最終的な合計は何か?
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
70 + 85 + 90 = 245.
リストが3個の要素でも300個の要素でも、同じトラバースループが機能する。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
ループはリストを名前で参照するため、汎用的である。
Change the contents
- Lists support operations that change their contents:
- append 追加 adds a new element to the end;
- insert adds an element at a chosen position; remove takes one out.
Total a list. scores holds [70, 85, 90]. Start total ← 0, then traverse: 70 → total 70; 85 → total 155; 90 → total 245. Final total 245. Append a fourth score and the same loop adds it too — no code change.
A list is an ordered collection of elements under one name, reached by index (often from 0). Traverse it with a loop to process every element, which keeps code general for any size. Lists also change: append, insert, and remove.