モジュール・標準ライブラリ計算問題

collectionモジュールのCounterを使用して、以下のコードを実行した場合、出力される最も出現回数が多い要素とその回数は何ですか? from collections import Counter text = 'banana' c = Counter(text) most_common = c.most_common(1) print(most_common)

A.[('a', 3)]← 正解
✓ 正解です。'banana'では'a'が3回、'n'が2回、'b'が1回出現します。most_common(1)は最も多い要素1つを返すので[('a', 3)]です。
B.[('b', 1)]
✗ 'b'は1回しか出現しません。最も出現回数が多いのは'a'(3回)です。
C.[('n', 2)]
✗ 'n'は2回出現しますが、'a'は3回出現します。most_common(1)は'a'を返します。
D.[('a', 2), ('n', 2)]
✗ most_common(1)は複数要素を返しません。最も多い1つの要素[('a', 3)]を返します。

Python 3 エンジニア認定基礎試験 の問題一覧