# Python sequence in list

**URL:** <https://forum.dynamobim.com/t/python-sequence-in-list/82752>\
**Category:** Revit\
**Tags:** python\
**Created:** [November 4, 2022, 1:48pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752 "2022-11-04T13:48:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [November 4, 2022, 1:48pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/1 "2022-11-04T13:48:10Z")

</div>

Hi all,

I guess this is an easy one, but I don’t know it anymore 😛  
I need a loop/while that’s start over after 3 values.

In this case I want 8 values:

PV op L1  
PV op L2  
PV op L3  
PV op L1  
PV op L2  
PV op L3  
PV op L1

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/1/a1f4d778d4600264f441e41f4350d4b0ceed97ee.png)

```auto
x = 1

nummers = []
while x < 100:
	nummers.append("PV op L"+ str(x))
	x += 1
	

OUT = nummers

```

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [November 4, 2022, 2:50pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/2 "2022-11-04T14:50:55Z")

</div>

here an example with `itertools.cycle()`

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/0/7022375fd6d906fc86c030474266e4b04c64e254.png)

Edit : code fixed

```auto
import sys
import itertools

out = []
if IN[0] is not None:
	cycle_x=itertools.cycle([1,2,3])
	for idx, x in enumerate(cycle_x):
		out.append("Toto L{}".format(x))
		# 'make break and avoid infinite loop
		if idx + 1 == IN[0] or idx > 9999:
			break
		
OUT = out

```

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [November 4, 2022, 3:02pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/3 "2022-11-04T15:02:19Z")

</div>

Hello, I tried like this,

```auto
# 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.
b=IN[0]
result=[]
a=[]

# Placer votre code au-dessous de cette ligne
num=(b[0]/3)*range(1,4)
num.append(1)
for i in num:
	result.append("Pv op L"+str(i))
# Affectez la sortie à la variable OUT.
OUT = result

```

I still have work to do 😀

thank you  
Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [November 4, 2022, 4:20pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/4 "2022-11-04T16:20:09Z")

</div>

hello again, when I copy / paste your code then save revit freeze, it comes from the python version which does not support itertools (I am under revit 2020)

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [November 4, 2022, 4:45pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/5 "2022-11-04T16:45:46Z")

</div>

Well seen, I guess the IN[0] was null  
I fixed my code in previous post

---

<div class="post-metadata">

**Author:** ![jw.vanasselt](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jw.vanasselt/32/133533_2.png) [@jw.vanasselt](https://forum.dynamobim.com/u/jw.vanasselt)\
**Post date:** [November 4, 2022, 4:52pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/6 "2022-11-04T16:52:05Z")

</div>

@c.poupin @christian.stan thank you both!  
It was harder than I thought haha

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [November 4, 2022, 4:53pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/7 "2022-11-04T16:53:28Z")

</div>

I had not yet connected in fact, a beautiful nozzle 😄 I am thank you

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [November 4, 2022, 8:30pm UTC](https://forum.dynamobim.com/t/python-sequence-in-list/82752/8 "2022-11-04T20:30:54Z")

</div>

Good evening, a designscript version (there is surely more efficient)

 ![04 Novembre forum anglais_4_2022-11-04_09-24-16](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b4edd8fdef5a0f3f5b332587c61c3127c65376c9.png)

code block:

```auto
n;
txt="PV op L";
arr=n%3>0?Math.Floor(n/3):n/3;
Sequence=DSCore.List.Cycle(1..3,arr);
Sup=n-arr*3;
ajout=Sup<=0?null:1..Sup;
serie=DSCore.List.AddItemToEnd(ajout,Sequence);
numb=DSCore.List.Clean(DSCore.List.Flatten(serie));
n<=0?"No List":txt+numb;

```

Cordially  
christian.stan
