Re: how to duplicate array entries

2010-01-17 Thread Munir
On Jan 11, 12:56 am, Munir wrote: > > I have an array  x=[1,2,3] > > > Is there an operator which I can use to get the result > > [1,1,1,2,2,2,3,3,3] ? > > > I tried x*3, which resulted in [1,2,3,1,2,3,1,2,3] > > Have you tried: > > y = x*3 > y.sort() > > Munir A single line version of this: sor

Re: how to duplicate array entries

2010-01-11 Thread Steven D'Aprano
On Mon, 11 Jan 2010 10:03:04 +0100, Alf P. Steinbach wrote: >>> A Python "list" is an array functionality-wise. >>> >>> If one isn't observant of that fact then one ends up with O(n^2) time >>> for the simplest things. >> >> Well that's certainly not true. Some operations may be O(N**2), but >> o

Re: how to duplicate array entries

2010-01-11 Thread Steven Howe
try --- #!/usr/bin/env python from types import ListType, IntType def array_expander( ar=None, ex=None ): if type( ex ) != IntType: return [] if ex <= 0: return [] if type( ar ) != ListType: return [] # working code starts he

Re: how to duplicate array entries

2010-01-11 Thread Alf P. Steinbach
* Chris Rebert: On Mon, Jan 11, 2010 at 2:20 AM, Alf P. Steinbach wrote: * Chris Rebert: On Mon, Jan 11, 2010 at 1:03 AM, Alf P. Steinbach wrote: * Steven D'Aprano: On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: * Paul Rudin: Sebastian writes: Using the term "array" accen

Re: how to duplicate array entries

2010-01-11 Thread Munir
> I have an array  x=[1,2,3] > > Is there an operator which I can use to get the result > [1,1,1,2,2,2,3,3,3] ? > > I tried x*3, which resulted in [1,2,3,1,2,3,1,2,3] Have you tried: y = x*3 y.sort() Munir -- http://mail.python.org/mailman/listinfo/python-list

Re: how to duplicate array entries

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 2:20 AM, Alf P. Steinbach wrote: > * Chris Rebert: >> On Mon, Jan 11, 2010 at 1:03 AM, Alf P. Steinbach wrote: >>> * Steven D'Aprano: On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: > * Paul Rudin: >> Sebastian writes: > Using the term "array

Re: how to duplicate array entries

2010-01-11 Thread Alf P. Steinbach
* Chris Rebert: On Mon, Jan 11, 2010 at 1:03 AM, Alf P. Steinbach wrote: * Steven D'Aprano: On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: * Paul Rudin: Sebastian writes: I have an array x=[1,2,3] In python such an object is called a "list". (In cpython it's implemented a

Re: how to duplicate array entries

2010-01-11 Thread Chris Rebert
On Mon, Jan 11, 2010 at 1:03 AM, Alf P. Steinbach wrote: > * Steven D'Aprano: >> >> On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: >> >>> * Paul Rudin: Sebastian writes: > I have an array  x=[1,2,3] In python such an object is called a "list". (

Re: how to duplicate array entries

2010-01-11 Thread Alf P. Steinbach
* Steven D'Aprano: On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: * Paul Rudin: Sebastian writes: 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.) I don't think the OP's terminology nee

Re: how to duplicate array entries

2010-01-11 Thread Peter Otten
Alf P. Steinbach wrote: > Re the thing I don't understand: it's the same in C++, people using hours > on figuring out how to do something very simple in an ungrokkable indirect > and "compiled" way using template metaprogramming stuff, when they could > just write a simple 'for' loop and be done w

Re: how to duplicate array entries

2010-01-11 Thread Sebastian
Thank you for your answers! I actually implemented it using for loops before I posted here, but I was curious if there is a more elegant solution (judging from the post, Alf will probably say, that for loops are already elegant). Sebastian -- http://mail.python.org/mailman/listinfo/python-list

Re: how to duplicate array entries

2010-01-11 Thread Steven D'Aprano
On Mon, 11 Jan 2010 08:56:36 +0100, Alf P. Steinbach wrote: > * Paul Rudin: >> Sebastian writes: >> >>> 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.) > > I don't think the OP's terminology

Re: how to duplicate array entries

2010-01-11 Thread Alf P. Steinbach
* Paul Rudin: Sebastian writes: 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.) I don't think the OP's terminology needs correction. A Python "list" is an array functionality-wise. If one isn't ob

Re: how to duplicate array entries

2010-01-10 Thread Steven D'Aprano
On Sun, 10 Jan 2010 22:21:54 -0800, Sebastian wrote: > Hi there, > > I have an array x=[1,2,3] You have a list. Python has an array type, but you have to "import array" to use it. > Is there an operator which I can use to get the result > [1,1,1,2,2,2,3,3,3] ? Not an operator, but you can d

Re: how to duplicate array entries

2010-01-10 Thread Gary Herron
Paul Rudin wrote: Sebastian 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

Re: how to duplicate array entries

2010-01-10 Thread Paul Rudin
Sebastian 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 yo

Re: how to duplicate array entries

2010-01-10 Thread Chris Rebert
On Sun, Jan 10, 2010 at 10:21 PM, Sebastian wrote: > Hi there, > > I have an array  x=[1,2,3] > > Is there an operator which I can use to get the result > [1,1,1,2,2,2,3,3,3] ? > > I tried x*3, which resulted in [1,2,3,1,2,3,1,2,3] > I also tried [[b,b,b] for b in x] which led to [[1,2,3],[1,2,3],

Re: how to duplicate array entries

2010-01-10 Thread Sebastian
On Jan 11, 4:21 pm, Sebastian wrote: > I also tried [[b,b,b] for b in x] which led to [[1,2,3],[1,2,3], > [1,2,3]] Sorry, I have to correct myself. The quoted line above resulted in [[1,1,1],[2,2,2],[3,3,3]] of course! Cheers, Sebastian -- http://mail.python.org/mailman/listinfo/python-list