Python 模擬試験

Python基礎 模擬試験 第4回 問38・11章 標準ライブラリめぐり Part II(リスト操作のためのツール)

bisect

次のコードを実行したときの出力として、正しいものを1つ選べ。

import bisect
scores = [(100, "perl"), (200, "tcl"), (400, "lua"), (500, "python")]
bisect.insort(scores, (300, "ruby"))
print(scores[2])
  1. A

    (400, 'lua')

  2. B

    (200, 'tcl')

  3. C

    (300, 'ruby')

  4. D

    (500, 'python')

正解と解説を見る

正解:C

bisect.insort() は、並べ替え済みのリストの順序を保ったまま要素を挿入する。

順実行する行実行後の変数
1`import bisect`—
2`scores = [(100, "perl"), (200, "tcl"), (400, …`scores = [(100, 'perl'), (200, 'tcl'), (400, 'lu…
3`bisect.insort(scores, (300, "ruby"))`scores = [(100, 'perl'), (200, 'tcl'), (300, 'ru…
4`print(scores[2])`scores = [(100, 'perl'), (200, 'tcl'), (300, 'ru…
結果実際の出力(300, 'ruby')

学習のポイント:リスト操作のためのモジュール(array、collections.deque、bisect、heapq)を押さえる。

この問題を演習で解く →

問題一覧へ

このサイトの問題は、各試験の公式に示された出題範囲に沿って作ったオリジナルの模擬問題です。本試験の問題ではありません。一般社団法人Pythonエンジニア育成推進協会の公式サービスではありません。