0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Python のリストを辞書に変換

Posted at

以下のリストを id をキーとする辞書に変換します。

books = [
    {'id': '1', 'title': 'Python 入門'},
    {'id': '2', 'title': 'PostgreSQL 入門'},
    {'id': '3', 'title': 'Nginx 入門'},
]

以下で変換を行います。

book_dict = {book['id']: book for book in books}
実行結果
{
  '1': {'id': '1', 'title': 'Python 入門'},
  '2': {'id': '2', 'title': 'PostgreSQL 入門'},
  '3': {'id': '3', 'title': 'Nginx 入門'}
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?