[Tutor] List Splicing

Emile van Sebille emile at fenx.com
Thu Jun 18 02:01:44 CEST 2009


On 6/17/2009 4:48 PM Robert Berman said...
> Emile,
> 
> Thank your for your comments. I do have a list running from 0-1000001.
> Yes, it is true, I only needed 0 - 100000 and yes I will change it.
> However, if you use primearray 

you haven't posted the primearray code...

<snip>
> 
> However, for the time being, can you perhaps share some suggestions on
> list splicing?

So, this part of your original post--
 > Out[53]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
 >
 > Since 3 is a prime, we can eliminate all multiples of 3. Within l1,
 > these are expressed as
 >
 > In [52]: l1[n+n:len(l1):n]
 > Out[52]: [6, 9, 12]
 >
 > when n = 3. ( do know 12 would have been eliminated by the prime
 > number 2)
 >
 > It would be great if I could say l1[n+n:len(l1):n] = 0

but you can say:

for ii in l1[n+n:len(l1):n]: l1[ii] = 0

Is something like that what you're after?

Emile



 > but obviously
 >
 > that will fail for obvious reasons. I am looking for the right hand
 > side of the statement to set a list within the list to all zeros.
---



More information about the Tutor mailing list