LoginSignup
7

More than 5 years have passed since last update.

dict同士を合体させた新しいdictを作る

Last updated at Posted at 2017-02-27

リストのように

dict_a + dict_b

と書いても辞書の合体はできないので自分でループを書いて合体させる処理を組まなければいけないかと思いきや、これで一発。

{**dict_a, **dict_b}

(コメントで教えてもらったのでさらに)

dict_a += dict_b

的なことがやりたければ

dict_a.update(dict_b)

とあいなります。
どっちも+, +=演算子でいーじゃねーかと思うんですけどね。

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
7