[newbie] copying identical list for a function argument

Rustom Mody rustompmody at gmail.com
Mon Feb 3 22:09:23 EST 2014


On Tuesday, February 4, 2014 3:06:24 AM UTC+5:30, 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?

Probably not what you are asking... But maybe you want to
look at repeat (and other stuff) in itertools


>>> from itertools import repeat

>>> zip(range(0,10), repeat("hi"))
[(0, 'hi'), (1, 'hi'), (2, 'hi'), (3, 'hi'), (4, 'hi'), (5, 'hi'), (6, 'hi'),
 (7, 'hi'), (8, 'hi'), (9, 'hi')]
 

IOW repeat give you "indefinite-data-repeat" just as "while True:..."
gives "indefinite-code-repeat"



More information about the Python-list mailing list