Click here to Skip to main content
15,314,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have 3 Lists cie, itemrange, pfinal
they are as below
#Note: cie values are integers, but I changed it just so my point gets clear
cie = [[a, b, c, d], [e, f, g, i], [j, k, l, m]]
itemrange = ["1", "2", "3"]
x = []

I have a string as the string contains a function name and an itemrange placeholder
Like so
functionName(1, 2)


I want to replace the 1, 2 into the nested items in cie and append it to x
Like so
x = [
  functionName(a,e) #first item from the first 2 indexes of cie
  functionName(b,f)
  functionName(c,g)
  #and so on...
]


What I have tried:

Python
statement = input()

for i in itemrange:
    if i in statement:
        for n in cie[int(i) - 1]:
            x.append(statement.replace(i, str(n)))

print(x)


This results the following output:
<pre lang="text">
inputText: functionName(1,2)

output:
x = 
[
    "functionName(0,2)",
    "functionName(0,2)",
    "functionName(0,2)",
    "functionName(0,2)",
    "functionName(1,0)",
    "functionName(1,0)",
    "functionName(1,1)",
    "functionName(1,1)",
]


This seems to be a problem with my for loop, as indeed it is replacing the values, but not recursively, how can I do it so it replaces multipl items in itemrange at the same time and stores them at once?
Posted
Comments
Maciej Los 12-Jan-22 15:33pm
   
Sorry, but your question is not clear. Please, be more specific and provide the body of functionName and expected output.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900