# List structure in Python

**URL:** <https://forum.dynamobim.com/t/list-structure-in-python/78904>\
**Category:** Lists-Logic\
**Tags:** python\
**Created:** [July 21, 2022, 6:44am UTC](https://forum.dynamobim.com/t/list-structure-in-python/78904 "2022-07-21T06:44:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![theshysnail](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/theshysnail/32/146653_2.png) [@theshysnail](https://forum.dynamobim.com/u/theshysnail)\
**Post date:** [July 21, 2022, 6:44am UTC](https://forum.dynamobim.com/t/list-structure-in-python/78904/1 "2022-07-21T06:44:13Z")

</div>

Hi all,

I am just trying basic python to find prime numbers between a range (lower and upper). But I couldn’t quite get the output in the form of list levels… I want the output lists (prime nums, count, sum) to be nested lists of the same lengths.

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

```auto
lower = IN[0]
upper = IN[1]
prime_num = []

for l,u in zip(lower, upper):
	for num in range(l, u+1):
		if num > 1:
			for i in range(2, num-1):
				if num % i == 0:
					break
			else:
				prime_num.append(num)
	
OUT = prime_num, len(prime_num), sum(prime_num)

```

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [July 21, 2022, 10:09am UTC](https://forum.dynamobim.com/t/list-structure-in-python/78904/2 "2022-07-21T10:09:37Z")

</div>

@theshysnail ,

> [@Getting primenumbers?](https://forum.dynamobim.com/t/getting-primenumbers/78140):
>
> Hello, is this not from math ? nums = IN[0] prims = [] for i in nums: prims.append(isprime(i)) Actually a lot more functions… how do i access them? prime(n) primefactors(z) primepi(n) sieve.primerange(n1,n2)

actually it was not solved… maybe you can load the packages

---

<div class="post-metadata">

**Author:** ![theshysnail](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/theshysnail/32/146653_2.png) [@theshysnail](https://forum.dynamobim.com/u/theshysnail)\
**Post date:** [July 21, 2022, 10:18am UTC](https://forum.dynamobim.com/t/list-structure-in-python/78904/3 "2022-07-21T10:18:41Z")

</div>

Thanks for linking the topic. Here I am just focusing on trying to manage my output lists into sublists instead of getting prime numbers.

---

<div class="post-metadata">

**Author:** ![theshysnail](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/theshysnail/32/146653_2.png) [@theshysnail](https://forum.dynamobim.com/u/theshysnail)\
**Post date:** [July 21, 2022, 10:42am UTC](https://forum.dynamobim.com/t/list-structure-in-python/78904/4 "2022-07-21T10:42:49Z")

</div>

After struggling a while, I was able to achieve it.

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

```auto
def tolist(input):
	result = input if isinstance(input, list) else [input]
	return result

lower = tolist(IN[0])
upper = tolist(IN[1])
prime_list = []

for l,u in zip(lower, upper):
	prime_num = []
	for num in range(l, u+1):	
		if num > 1:	
			for i in range(2, num-1):
				if num % i == 0:
					break
			else:
				prime_num.append(num)
	prime_list.append(prime_num)

p_count = []
p_sum = []

for i in prime_list:
	p_count.append(len(i))
	p_sum.append(sum(i))
	
OUT = prime_list, p_count, p_sum

```
