<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>Bablovia</author_name>
  <author_url>https://blog.hatena.ne.jp/Bablovia/</author_url>
  <blog_title>イヌツムリのメモ</blog_title>
  <blog_url>https://bablovia.hatenablog.com/</blog_url>
  <categories>
    <anon>Python</anon>
    <anon>トラブル</anon>
  </categories>
  <description>はじめに 久しぶりにpythonを触ったら、ハマった。 多次元リストを生成して、そのうちの1つ値を変更すると、 他の列の値も変更されてしまった。 初期化方法がまずく、1つの列をコピーして多次元リストとしていたことが原因だった。 リスト内包表記すれば、それぞれの列を別のオブジェクトとして生成してくれるので同じ問題が発生しない。 (そういえばそうやった...) ハマった例 よくあるリストの初期化方法として下記の方法がある。 dp = [0] * 3 print(dp) # [0, 0, 0] dp[0] = 1 # [1, 0, 0] しかし、これがハマりどころで、同じようにして3 * 3のリスト…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fbablovia.hatenablog.com%2Fentry%2F2021%2F05%2F25%2F142320&quot; title=&quot;pythonの多次元リストの罠にハマった - イヌツムリのメモ&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2021-05-25 14:23:20</published>
  <title>pythonの多次元リストの罠にハマった</title>
  <type>rich</type>
  <url>https://bablovia.hatenablog.com/entry/2021/05/25/142320</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
