Note that there are some explanatory texts on larger screens.

plurals
  1. POList contents changing with each iteration
    primarykey
    data
    text
    <p>So I am working on making a dictionary of subway stations in Boston and their neighbors for a bigger program. Each station belongs to a line, like blue or red, and these lines make up the whole entire subway system in Boston. But I am having trouble. here is my code so far:</p> <pre><code> for i in range(len(tuples)): for x in range(len(tuples[i][1])): print tuples neighbors=[] station=tuples[i][1][x] if tuples[i][1][-1]==station and station not in duplicates: line=0 for item in tuples: if station in item[1]: line=item[0] break neighbors.append((tuples[i][1][-2],line)) elif tuples[i][1][0]==station and station not in duplicates: line=0 for item in tuples: if station in item[1]: line=item[0] break neighbors.append((tuples[i][1][1],line)) elif station in duplicates: line=[] for item in tuples: if station in item[1]: line.append((item[0],tuples.index(item))) neighbors=[(tuples[i][1][x+1],tuples[i][1][x-1],line[0][0]),(tuples[line[1][1]][1][x+1],tuples[line[1][1]][1][x-1],line[1][0])] else: line=0 for item in tuples: if station in item[1]: line=item[0] break neighbors.append((tuples[i][1][x+1],tuples[i][1][x-1],line[0][0])) for neighbor in neighbors: subdict[station]={} for i in range(len(neighbor)-1): subdict[station].update({neighbor[i]:neighbor[-1]}) </code></pre> <p>So I ran it and got a syntax error indicating an index out of range error. This made no sense but then I printed out the individual stations and lists in tuple, and found that they kept changing. So in one iteration, the list of stations in one subway line was the same as expected, but then after that it was completely different. Only the first station in the list in one subway line remained the same; the rest were from different lines of the Boston subway.</p> <p>So can someone tell me whats going on in my code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload