[newbie] copying identical list for a function argument

Gary Herron gary.herron at islandtraining.com
Mon Feb 3 17:06:16 EST 2014


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
>




More information about the Python-list mailing list