Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'method.': 0.05; '[0]': 0.07; 'python': 0.09; '[0,': 0.09; 'before.': 0.09; 'lst': 0.09; 'cc:addr:python-list': 0.10; 'thread': 0.11; '(2,': 0.16; '0],': 0.16; "['a',": 0.16; '[2,': 0.16; 'benjamin': 0.16; 'cc:name:python list': 0.16; 'integer.': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'subject:skip:i 10': 0.22; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'values': 0.26; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; '"no': 0.29; '>>>>': 0.29; 'that.': 0.30; 'e.g.': 0.30; 'error': 0.30; 'lists': 0.31; 'could': 0.32; 'problem': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'described': 0.35; 'expected': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'bad': 0.37; 'does': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'subject:-': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'kind': 0.61; 'more': 0.63; 'for:': 0.64; 'total': 0.65; 'oscar': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=zpGq6NyeC7IbLOJRaaM27MAaCOBOdP26GFp7Dqf1C2M=; b=exyFVFwkkm8w8Hm0mZp68hX8HynkWC6ErPyb2LFQCxcNHWZzDWWByBnitmofu8nJln BWwF71oclk+5QlY0ZWrPhJnLUSv3SXQlEekaKQrzA16PijZ4Uuo3FRS10j4uPIafi5J6 NvT23UOEORiTWbeMsFVm/Ou/+FYb1JgaysCFWMmwvd3zRCykHrEqG2TNMjJBwaCgV10U 9/Y48x09jUsDYAH0duQPcPkaIcBCoZUtf0nzt+eGikUYd/78f/J4x6HOMIw0IlnnHoii ZVVK/i1oWfyHcwl22XORKuybXTYemperSv1iBs8POLYmxxZyquI/lYo1j+51AlVDUIyQ NOaw== MIME-Version: 1.0 In-Reply-To: References: <50978323$0$6908$e4fe514c@news2.news.xs4all.nl> <5098A55C.3090201@r3dsolutions.com> <5098C873.2000200@r3dsolutions.com> <509982CA.7050701@r3dsolutions.com> Date: Wed, 7 Nov 2012 14:00:27 +0000 Subject: Re: Multi-dimensional list initialization From: Oscar Benjamin To: Joshua Landau Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List , Gregory Ewing X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352296829 news.xs4all.nl 6903 [2001:888:2000:d::a6]:52622 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32886 On 7 November 2012 13:39, Joshua Landau wrote: > > On 7 November 2012 11:11, Oscar Benjamin wrote: >> >> A more modest addition for the limited case described in this thread could >> be to use exponentiation: >> >> >>> [0] ** (2, 3) >> [[0, 0, 0], [0, 0, 0]] > > Hold on: why not just use multiplication? > >>>> [0] * (2, 3) > > is an error now, and it makes total sense. Additionally, it's not breaking > the "no copy -- _ever_" rule because none of the lists existed before. The > values inside the list would be by reference, as before, so lst * (x,) would > be the same as lst * x if x is an integer. The problem is that this operation is asymmetric. Currently int/list multiplication is commutative so that: ['a', 'b'] * 2 == 2 * ['a', 'b'] If you use this kind of multiplication what happens to the other cases? e.g. what do you give for: >>> [0] * [2, 3] >>> [2, 3] * [0] >>> (2, 3) * [0] >>> (2, 3) * (4, 5) and so on. Although Python does not guarantee commutativity of multiplication in general I think that since for lists it has always been commutative it would be bad to change that. Exponentiation is expected to be asymmetric and is currently unused so there is no ambiguity. The problem is if someone has already subclassed list and added an exponentiation method. Oscar