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


Groups > comp.lang.python > #65386

Re: [newbie] copying identical list for a function argument

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
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; 'subject:: [': 0.04; 'syntax': 0.04; 'argument': 0.05; 'latter': 0.09; 'lst': 0.09; 'repeated': 0.09; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'prefered': 0.16; 'skip:[ 30': 0.16; 'wrote:': 0.18; 'subject:] ': 0.20; '(the': 0.22; 'python?': 0.22; 'simpler': 0.24; 'appreciated': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'compared': 0.30; 'subject:list': 0.30; 'inspect': 0.31; 'jean': 0.31; 'version': 0.36; 'really': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'depends': 0.38; 'e.g.': 0.38; 'to:addr :python-list': 0.38; 'realize': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'times': 0.62; 'different': 0.65; 'received:50.22': 0.84
Date Mon, 3 Feb 2014 15:51:23 -0600
From Tim Chase <python.list@tim.thechases.com>
To python-list@python.org
Subject Re: [newbie] copying identical list for a function argument
In-Reply-To <df3d41dd-222d-4a05-b9de-377d67b77bda@googlegroups.com>
References <df3d41dd-222d-4a05-b9de-377d67b77bda@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Authenticated-Sender tim@thechases.com
X-OutGoing-Spam-Status No, score=-6.0
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
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.6370.1391468667.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391468667 news.xs4all.nl 2923 [2001:888:2000:d::a6]:50481
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65386

Show key headers only | View raw


On 2014-02-03 13:36, Jean Dupont wrote:
> I have a list like this:
> [1,2,3]
> 
> The argument of my function should be a repeated version e.g.
> [1,2,3],[1,2,3],[1,2,3],[1,2,3] (could be a different number of
> times repeated also)
> 
> what is the prefered method to realize this in Python?
> 
> any help would be really appreciated

It depends on whether you want the contained list to be the *same*
list or *copies* of that list.  You can do either of the following:

  lst = [1,2,3]
  dupes1 = [lst[:] for _ in range(5)]
  dupes2 = [lst for _ in range(5)]
  dupes3 = [lst] * 5

The dupes2 and dupes3 should be the same (the latter is a simpler
syntax for it): each contains the same list multiple times.  To see
this, do

  lst.append(4)

and then inspect dupes1 compared to dupes2/dupes3.

-tkc

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


Thread

[newbie] copying identical list for a function argument Jean Dupont <jeandupont314@gmail.com> - 2014-02-03 13:36 -0800
  Re: [newbie] copying identical list for a function argument Gary Herron <gary.herron@islandtraining.com> - 2014-02-03 14:06 -0800
  Re: [newbie] copying identical list for a function argument Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-03 22:19 +0000
    Re: [newbie] copying identical list for a function argument Jean Dupont <jeandupont115@gmail.com> - 2014-02-04 01:14 -0800
  Re: [newbie] copying identical list for a function argument Tim Chase <python.list@tim.thechases.com> - 2014-02-03 15:51 -0600
  Re: [newbie] copying identical list for a function argument Rustom Mody <rustompmody@gmail.com> - 2014-02-03 19:09 -0800

csiph-web