Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; '"""': 0.07; '[1,': 0.09; 'constructor': 0.09; 'next,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'separating': 0.09; 'subject:into': 0.09; 'subject:method': 0.09; 'worked.': 0.09; 'wrote': 0.14; 'creates': 0.14; "'b',": 0.16; '(1,': 0.16; "['a',": 0.16; '[*]': 0.16; 'brackets': 0.16; 'brackets,': 0.16; 'commas:': 0.16; 'denote': 0.16; 'elements,': 0.16; 'given,': 0.16; 'ie.': 0.16; 'iterable': 0.16; 'iteration,': 0.16; 'iterator': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'returned,': 0.16; 'sequence,': 0.16; 'tuple': 0.16; 'ways:': 0.16; 'elements': 0.16; 'items.': 0.19; 'passing': 0.19; '>>>': 0.22; 'subject: .': 0.24; 'header:X -Complaints-To:1': 0.27; 'tried': 0.27; 'fixed': 0.29; 'list:': 0.30; 'subject:list': 0.30; 'container': 0.31; 'object.': 0.31; 'reduced': 0.31; 'lists': 0.32; 'another': 0.32; 'running': 0.33; 'problem': 0.35; 'but': 0.35; 'add': 0.35; 'similar': 0.36; 'example,': 0.37; 'list': 0.37; 'e.g.': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'then,': 0.60; 'subject: ': 0.61; 'today.': 0.61; 'new': 0.61; 'making': 0.63; 'finally': 0.65; 'here': 0.66; 'frank': 0.68; 'square': 0.74; 'skip:n 40': 0.81; 'circles': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: "Frank Millman" Subject: Re: Passing a list into a list .append() method Date: Tue, 9 Sep 2014 08:53:20 +0200 References: X-Gmane-NNTP-Posting-Host: 197.89.14.134 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.4657 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4913 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: 66 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410245614 news.xs4all.nl 2857 [2001:888:2000:d::a6]:36286 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77713 "JBB" wrote in message news:loom.20140909T073428-713@post.gmane.org... >I have a list with a fixed number of elements which I need to grow; ie. add > rows of a fixed number of elements, some of which will be blank. > > e.g. [['a','b','c','d'], ['A','B','C','D'], ['', 'aa', 'inky', ''], ['', > 'bb', 'binky', ''], ... ] > > This is a reduced representation of a larger list-of-lists problem that > had > me running in circles today. > > I think I figured out _how_ to get what I want but I am looking to > understand why one approach works and another doesn't. > [...] > > Next, I tried passing it as list(tuple(blank_r)) which worked. Then, I > finally settled on 2) where I dispensed with the tuple conversion. > I am sure that someone will give you a comprehensive answer, but here is a quick clue which may be all you need. >>> x = [1, 2, 3] >>> id(x) 16973256 >>> y = x >>> id(y) 16973256 >>> z = list(x) >>> id(z) 17004864 Wrapping a list with 'list()' has the effect of making a copy of it. This is from the docs (3.4.1) - """ Lists may be constructed in several ways: - Using a pair of square brackets to denote the empty list: [] - Using square brackets, separating items with commas: [a], [a, b, c] - Using a list comprehension: [x for x in iterable] - Using the type constructor: list() or list(iterable) The constructor builds a list whose items are the same and in the same order as iterable's items. iterable may be either a sequence, a container that supports iteration, or an iterator object. If iterable is already a list, a copy is made and returned, similar to iterable[:]. [*] For example, list('abc') returns ['a', 'b', 'c'] and list( (1, 2, 3) ) returns [1, 2, 3]. If no argument is given, the constructor creates a new empty list, []. """ I marked the relevant line with [*] HTH Frank Millman