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
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
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
* 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
> 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
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
* 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
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".
(
* 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
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
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
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
* 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
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
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
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
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],
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
18 matches
Mail list logo