問題

Pythonで、以下のようなリストmy_listとindexes_to_removeがある。

my_list = [10, 20, 30, 40, 50, 60, 70, 80, 90]
indexes_to_remove = [2, 5, 7]

indexes_to_removeの要素はリストmy_listのインデックスを表しており、この3つのインデックスに対応する要素をmy_listから削除するための方法として、適切なものは次のうちどれか。

コード1:

for i in indexes_to_remove: 
    del my_list[i]

コード2:

del my_list[indexes_to_remove]

コード3:

for i in sorted(indexes_to_remove, reverse=True): 
    del my_list[i]

コード4:

del my_list[min(indexes_to_remove):max(indexes_to_remove)]

 

選択肢

(a) コード1

(b) コード2

(c) コード3

(d) コード4

  • a
  • b
  • c
  • d

Python del文に関する知識問題(2)

答え

(c)

解説

解説はありません。

テスト一覧

スキルテストが提供しているテストの一覧です。ぜひ学習や実力チェックに役立ててください。