if you're going for probability based percentage, then just do that:

import random

def randomPercentage(data,percentage):

    for i in data:

        if random.random()<percentage:

            yield i


print list(randomPercentage(selectedList,0.7))


also, another very short answer would be just randomizing your list and getting a part of it:

import random
import math
random.shuffle(selectedList)
print selectedList[:int(math.ceil(len(a)*0.7))]


On 2011.03.20 22:51, Ling wrote:
Hey guys:

   Need some algorithm help if possible..

   Say I have 1000 points in a sorted list, and I want to select a
given portion of the points in the list, for example, 70% of it. Don't
need to be perfectly accurate, but the 70% have to be pretty much
evenly distributed among the 1000 points.

   I am doing a step selection right now, which is something like:



selectedList = []
remain = 0
while i<  1000:
     step = int(1/0.7 + remain)
     remain = 1/0.7 + remain - step
     selectedList.append(pointsList[i])
     i += step


the step selection works, but just wonder if there is any better/
faster solution I can borrow from you guys.

   Any suggestions would be really appreciated.

-ling



--
Viktoras
www.neglostyti.com

--
http://groups.google.com/group/python_inside_maya

Reply via email to