I am now working on a python algorithm. I have a for loop to generate some numbers. These numbers will be used as indices to generate strings.
I have these codes:
val=4
ind=[]
for i in range(1,7):
for j in range(val,val+i):
val = val+1
ind.append(j)
if(i < 6):
boundNode.insert(j, 'x%d' % (j-(2*i+1)))
constraint_sty1 = str(boundNode[j]) + " + " + str(boundNode[j+1])
val = j + 3
The problem here is: The boundNode[j] works to get what I demand, However, boundNode[j+1] encounters error, It seems that j+1 has been viewed as a sign to do some other operations here. I tried to only print(j+1), it can also print the indices I want. I'd like to know if there's any solution to this.
This is the output of print(boundNode[j]) and print(boundNode[j+1])
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 20 23 25 26 27 28
12 16 16 19 19 19 22 22 22 22 25 25 25 25 25 23 25 26 27 28 28
To define the larger picture, boundNode is a list like this:
boundNode = [0, 4, 6, 7, 12, 9, 16, 11, 19, 13, 22, 14, 25, 15, 20, 23, 25, 26, 27, 28, 28]
I use 2 for loops to generate indices like 4, 7, 8 , 11, 12 , 13 ... and put x1 to x15 into boundNode. And the boundNode is now like:
[0, 4, 6, 7, 'x1', 12, 9, 'x2', 'x3', 16, 11, 'x4', 'x5', 'x6', 19, 13, 'x7', 'x8', 'x9', 'x10', 22, 14, 'x11', 'x12', 'x13', 'x14', 'x15', 25, 15, 20, 23, 25, 26, 27, 28, 28]
What I am going to next is to use the indices to point to bound nodes and generate strings. Everything is going well except boundNode[j+1]
boundNode[j+1]gets overflow itemprint(boundNode[j])is more thanprint(boundNode[j+1]). Will this be useful to explain what happened?boundNodelist? If so then after showing the last element of j, it shouldn't findj+1indexboundNode? What isval? What isind? Neither is defined in your question.