Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72328

Re: Yet another "simple" headscratcher

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.049
X-Spam-Evidence '*H*': 0.90; '*S*': 0.00; 'see:': 0.07; '[0]': 0.09; 'def': 0.12; 'equal.': 0.16; 'fails.': 0.16; 'subject:simple': 0.16; 'url:faq': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'josh': 0.31; 'class': 0.32; 'lists': 0.32; 'url:python': 0.33; 'fri,': 0.33; 'except': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'should': 0.36; 'handle': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'url:3': 0.61; 'happen': 0.63; 'different': 0.65; '30,': 0.65; 'here': 0.66
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=ErPJdUA+s4nxSGfuo5Wbb9/72QnJ3E/jfkFQG+6cg6U=; b=sfYDazAToaeG5UBZkCJUdOsx7VZ3pkskvShVb+OeRE1KqU33743G8vqvJU+vqvoKjO mLxUqn4n7Dshe51uC0F7seGfCppNnulpUyo93Lqav7fmBRvaKVUtyMsMZRxKBts8ug0o BOvN6dxXsabtH1QFjl5cbLGW8TDRLHjzeO5OjGNiSUbq8I+sSt0PZeFka8spiY+Iwgx5 FC67vbpG0mf1za/IA9v4IyJ+QuCWto1gMG+7I19NagEINCZhSXXRw8PsEL53ebDtC3Ns 3tm/3kCMD5r/2vlYhjxp5ItL+UGvcGy1zR1CGtw0uMniChdYq7Tm0r0l9tQ6nN8666+A fbHg==
X-Received by 10.236.35.4 with SMTP id t4mr319178yha.155.1401508480491; Fri, 30 May 2014 20:54:40 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <a7dbde77-6bec-4b04-a940-5e8beb926232@googlegroups.com>
References <a7dbde77-6bec-4b04-a940-5e8beb926232@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Fri, 30 May 2014 21:54:00 -0600
Subject Re: Yet another "simple" headscratcher
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10504.1401508949.18130.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401508949 news.xs4all.nl 2882 [2001:888:2000:d::a6]:53200
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72328

Show key headers only | View raw


On Fri, May 30, 2014 at 9:38 PM, Josh English
<Joshua.R.English@gmail.com> wrote:
> I am trying to whip up a quick matrix class that can handle multiplication.
>
> Should be no problem, except when it fails.
>
> [SNIP]
>
> def zero_matrix(rows, cols):
>     row = [0] * cols
>     data = []
>     for r in range(rows):
>         data.append(row)

Each row of the matrix that you create here is the *same* list, not
different lists that happen to be equal.  So when you mutate one row,
you mutate all of them.  See:
https://docs.python.org/3/faq/programming.html#how-do-i-create-a-multidimensional-list

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Yet another "simple" headscratcher Josh English <Joshua.R.English@gmail.com> - 2014-05-30 20:38 -0700
  Re: Yet another "simple" headscratcher Josh English <Joshua.R.English@gmail.com> - 2014-05-30 20:55 -0700
  Re: Yet another "simple" headscratcher Gary Herron <gary.herron@islandtraining.com> - 2014-05-30 20:57 -0700
  Re: Yet another "simple" headscratcher Ian Kelly <ian.g.kelly@gmail.com> - 2014-05-30 21:54 -0600
    Re: Yet another "simple" headscratcher wxjmfauth@gmail.com - 2014-05-30 23:46 -0700

csiph-web