how to duplicate array entries
Paul Rudin
paul.nospam at rudin.co.uk
Mon Jan 11 02:07:07 EST 2010
Sebastian <sebastian.langer at gmx.de> writes:
> Hi there,
>
> I have an array x=[1,2,3]
In python such an object is called a "list".
(In cpython it's implemented as an automatically resizable array.)
>
> Is there an operator which I can use to get the result
> [1,1,1,2,2,2,3,3,3] ?
There's no operator that will give you that directly - but there are
plenty of one-liners that will yield that list.
e.g:
>>> list(itertools.chain(*([x]*3 for x in [1,2,3])))
[1, 1, 1, 2, 2, 2, 3, 3, 3]
More information about the Python-list
mailing list