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


Groups > comp.lang.python > #65381

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

Date 2014-02-03 14:06 -0800
From Gary Herron <gary.herron@islandtraining.com>
Subject Re: [newbie] copying identical list for a function argument
References <df3d41dd-222d-4a05-b9de-377d67b77bda@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.6367.1391465505.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 02/03/2014 01:36 PM, 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)

That's not very clear.  You say "The" argument (singular; meaning 1) but 
then show what seems to be four arguments.  Can you show us the function 
you mention.

A number of things come to mind:

 >>> 4*[[1,2,3]]
[[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]

so fn(n*[[1,2,3]]) might do for a single parameter function
   def fn(L):
       ...

On the other hand expanding a sequence into individual parameters:
     fn(*(4*[[1,2,3]]))  # note extra * preceding the arg
willl be a valid call for
   def fn(a,b,c,d):
     ...

I'm sure other interpretations of your question are possible.

Gary Herron




>
> what is the prefered method to realize this in Python?
>
> any help would be really appreciated
>
> kind regards,
> jean
>

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