Skip to Content
ハイパフォーマンスPython 第2版
book

ハイパフォーマンスPython 第2版

by Micha Gorelick, Ian Ozsvald, 中山 光樹
April 2023
Intermediate to advanced
452 pages
7h 21m
Japanese
O'Reilly Japan, Inc.
Content preview from ハイパフォーマンスPython 第2版

3章リストとタプル

3章を読めば以下の問いに答えられるようになる
  • リストとタプルの長所は?
  • リストとタプルの探索の計算量は?
  • その計算量になる理由は?
  • リストとタプルの違いは?
  • リストに要素を追加するときの動作は?
  • リストとタプルの使い分けはどうする?

 効率的なプログラムを書くときにもっとも重要なことは、使用するデータ構造の特徴を理解することです。実際、高性能プログラミングとは、データをどのように操作しようとしているのかを知り、その操作を高速にできるデータ構造を採用することと言っても過言ではありません。本章では、リストとタプルが得意な操作と、その使用法を説明します。

 リストとタプルは配列というデータ構造のクラスに属します。配列とは、何らかの固有な順序で並んだ一連のデータです。通常、この種のデータ構造では、要素の相対的な順序付けは、要素そのものと同じくらい重要です。また、順序が事前にわかっていることが重要です。なぜなら、配列上のデータが特定の位置にあることがわかっていれば、O(1)で探索できるからです†1。さらに、配列はさまざまな方法で実装でき、方法によって機能や特徴が異なります。そのため、Pythonではリストとタプルという2種類の配列が用意されています。リストは動的な配列で、格納するデータを変更したりサイズを変更したりできます。一方、タプルは静的な配列で、内容は固定されていて不変です†2

†1 O(1)では、Big O記法を用いて、アルゴリズムの効率の良さを表しています。このトピックに関して知りたい場合、Sarah Chima氏によるdev.toの投稿(https://oreil.ly/qKUwZ)や、Thomas H. Cormen氏らによる『Introduction ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

ハイパフォーマンスPython

ハイパフォーマンスPython

Micha Gorelick, Ian Ozsvald, 相川 愛三
Rクックブック 第2版

Rクックブック 第2版

J.D. Long, Paul Teetor, 大橋 真也, 木下 哲也
Node.jsデザインパターン 第2版

Node.jsデザインパターン 第2版

Mario Casciaro, Luciano Mammino, 武舎 広幸, 阿部 和也
PythonによるWebスクレイピング 第2版

PythonによるWebスクレイピング 第2版

Ryan Mitchell, 黒川 利明, 嶋田 健志

Publisher Resources

ISBN: 9784873119908Other