Count a value
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
This one builds on a lesson you haven't finished yet. Do that lesson first: · これはまだ完了していないレッスンの先にある内容です。まずはそのレッスンを済ませてください:
Python Basics · Functions →
English
Count a value
Count how often one value appears in a list.
Loop over the list and compare each item with target. It is the counter pattern again, with the condition item == target, and it works for words as well as numbers.
日本語
値のカウント
リスト内で特定の値が出現した回数をカウントします。
リストを巡り、各要素を target と比較します。これは条件 item == target を持つカウンタのパターンであり、数字だけでなく文字列にも適用できます。
Write count_value(items, target) that returns how many times target appears in items, without using .count().
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。