Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed6.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'interpreted': 0.07; 'nested': 0.07; 'objects,': 0.07; 'mutable': 0.09; 'rows': 0.09; 'tuple': 0.09; '10x10': 0.16; '[[]]': 0.16; 'distinct': 0.16; 'identities.': 0.16; 'innermost': 0.16; 'shallow': 0.16; 'uncommon': 0.16; 'wrote:': 0.17; 'copied': 0.17; 'element': 0.17; 'meant': 0.21; 'latter': 0.22; 'subject:skip:i 10': 0.22; 'work,': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'andrew': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'objects': 0.29; 'probably': 0.29; 'received:209.85.215.46': 0.30; 'writes': 0.30; 'expect': 0.31; 'lists': 0.31; 'not.': 0.32; 'to:addr:python-list': 0.33; 'themselves': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'lists.': 0.35; 'nov': 0.35; 'especially': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'but': 0.36; 'should': 0.36; 'level': 0.37; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:-': 0.40; 'header:Received:5': 0.40; 'containing': 0.61; 'different': 0.63; 'dict,': 0.84; 'to:name:python': 0.84 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=BHEDeFytyxod8m6JeYZFXmtmKaboFQ4kiZs1Y4zdzj0=; b=UQUsjwXeSJiUyOYtalr/eeg5G2mw1iPnuzkJa9/wO7k2zrjdCHNlaub4Blzjb1auVL mtfXwR+z4mhIhJGEeWZI86SptkR+ZGLc0X2WHOQ/Tbg128K520O85npwh3QYQEyzG9Bk PjR3VGVJ1dmTVDbH7TVGreGUagTzNT18V++oCkV12b/5RWsA7AB7oQxiTP20zRueGbui 8AF4umjVQRMi3KTMYIPA9KBV99eIrbiICsmqL7lcJVKFvSrViP1GJTdqWf00fLvgweV0 RLCDuJTvaalYcd3HKXM7ikHKY7Mz8k5sG1UH4ImYOHFH6A9MFOW/01cYQ/5aHRc/A6xc rJNw== MIME-Version: 1.0 In-Reply-To: <509982CA.7050701@r3dsolutions.com> References: <50978323$0$6908$e4fe514c@news2.news.xs4all.nl> <5098A55C.3090201@r3dsolutions.com> <5098C873.2000200@r3dsolutions.com> <509982CA.7050701@r3dsolutions.com> From: Ian Kelly Date: Tue, 6 Nov 2012 15:46:52 -0700 Subject: Re: Multi-dimensional list initialization To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352242045 news.xs4all.nl 6877 [2001:888:2000:d::a6]:45768 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32844 On Tue, Nov 6, 2012 at 2:36 PM, Andrew Robinson wrote: > I meant all lists are shallow copied from the innermost level out. > Equivalently, it's a deep copy of list objects -- but a shallow copy of any list contents except other lists. Why only list objects, though? When a user writes [[]] * 10, they probably want a list containing ten distinct nested lists. Likewise, when a user writes [{}] * 10, they probably want a list containing ten distinct dicts, which is not at all an uncommon thing to want. It seems very inconsistent that the former should work while the latter should not. This is especially true when you start mixing the two paradigms; the user might expect [[{}] * 10] * 10 to create a a 10x10 matrix where each element is a distinct dict, but this still would not work, even though the nested lists would all have different identities. What about ([],) * 10? This is perhaps best interpreted as a request to create a matrix of ten rows where the rows themselves are mutable but the collection of rows is not. If list multiplication were to copy nested lists, then should tuple multiplication do the same?