# List Output Problem

Hello everyone, I am very new in the programming field, and recently l had a problem of the output in the list to be repeated according to a value in another list, very appreciated for any hint or help

this is the result that I am trying to achieve

here is my try for the code

``````# Load the Python Standard and DesignScript Libraries
import sys
import clr
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
List = IN
Count = IN

output = []
# Place your code below this line
for i in range(0,len(List)):
temp = []
for x in range(0,len(Count[i])):
temp1 = []
temp1.append(List[i][x])
temp.append(temp1)
output.append(temp)

# Assign your output to the OUT variable.
OUT = output
``````

Hello Hamzeh.

It is difficult to make sense of what you are looking for. The image you posted does not have any useful information about the problem.

What criteria are there?
When do you want to repeat a value?

Hello Sky020, as i said sorry i am not familiar with coding and its my second try to code , so i am tryin to learn python yet, the criteria of repeating its according to the value if its one then output the item at that index one time and so on .
i am working on dynamo for revit and in this task is needed to repeat the item in List1 according to the value in List2 , maybe this would help to explain how i got the list and what was the result that i got

Likely you’ve solved this already. I’m posting the solution from what I can understand, so that if others view this thread they can learn from it too.

The first step is to understand your problem.

``````#repeat item from list 1 x number of times
#x is in list 2, access value in list 2
#store extended output in a new list
``````

I find it helpful when I’m having a problem, to write it as comments, then expand each comment into working code.

What we can gather from this problem, we need x first in order to apply it to list 1.

``````#access value in list 2
for x in list_2:
#access indice in list one
#repeat value in list_1 x times
#store extended values in a new list
``````

From our problem, we can understand that indice from list_2 is a direct mapping to what we apply at the same indice to list_1. So we added that as part of our problem.

We can use enumerate in our for loop, to get the indice, then use that value to extract that same position from list_1.

``````#get x from list 2, indice from list 2 maps to indice in list 1
for indice, int_x in enumerate(list_2):
#repeat item in list_1 x times
#store extended values in a new list
``````

Lets handle our new list.

``````#list to hold extended values
expanded_list = []
for indice, int_x in enumerate(list_2):
#repeat item in list_1 x times
expanded_list.append(list_1[indice])
``````

Pretty much everything is written out, the last thing we need to do is the repeating action of appending x number of times.

``````#Extend list 1 values x number of times, x is from list 2
extended_list = []
for indice, int_x in enumerate(list_2):
for _dummy_y in range(x):
extended_list.append(list_1[indice])
``````