Method Python Faster exist?

Hello,
Is there a method (in Python or Designscript) faster than those applied here.

To create a list of numbers relative to a median with a defined step.

DesignScript:

Val_center;
Step;
Nb_val;
Val_center-Nb_val*Step..
Val_center+Nb_val*Step..
Step;

Python script:

# Charger les bibliothèques DesignScript et Standard Python
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Les entrées effectuées dans ce noeud sont stockées sous forme de liste dans les variables IN.
Center=IN[0]
Step=IN[1]
Number=int(IN[2])
seq=range(-Number,Number+1)
Result=[]

# Placer votre code au-dessous de cette ligne
for i in seq:
	R=Center+i*Step
	Result.append(R)
# Affectez la sortie à la variable OUT.
OUT = Result

Thanks

Cordially
christian.stan

Hi @christian.stan

try this

val_center = 25
step = 2.5
number = 5

def d_range(val_center, number, step):
    x, end = val_center - step * number, val_center + step * number
    while x <= end:
        yield x
        x += step

list(d_range(val_center, number, step))
2 Likes

Hello, after reading about the generators I think I have understood the way to do it

Thank you for sharing and providing knowledge.

Cordially
christian.stan

1 Like