How to do this?

Dave Angel davea at davea.name
Mon Apr 1 07:53:44 EDT 2013


On 04/01/2013 07:08 AM, Ana Dionísio wrote:
> [0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0]


I'd do
res = "[0 0 0 0 0.17 0.17 0.17 0.17 0 0 0 0.17 0.17 0.17 0 0 0 0 0 0 0]"

Unless there's a pattern you're trying to accomplish (like maybe next 
time you want to do "it" for a list of two million items), there's 
little point in writing code to do what you've already predetermined. 
And if there is a pattern, you'd probably better let us know.

But if it's for fun,



vt = [0] * 21
for index, val in enumerate(vt):
     if 3<index<8 or 10<index<14:
         vt[index] = 0.17


or


vt = [0] * 21
for index, val in enumerate(vt):
     if index in (4,5,6,7,11,12,13):
         vt[index] = 0.17


-- 
-- 
DaveA



More information about the Python-list mailing list