Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4054454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:34:38+00:00 2026-05-20T14:34:38+00:00

Ok, I have changed my code a little, but I am getting confused on

  • 0

Ok, I have changed my code a little, but I am getting confused on what variable names should be passed to my nearestNeighbour function. These two functions work ok:

infinity = 1000000
invalid_node = -1
startNode = 0

#Values to assign to each node
class Node:
     def __init__(self):
       self.distFromSource = infinity
       self.previous = invalid_node
       self.visited = False

#read in all network nodes
#node = the distance values between nodes
def network():
    f = open ('network.txt', 'r')
    theNetwork = [[int(networkNode) for networkNode in line.split(',')] for line in f.readlines()]
    #theNetwork = [[int(node) for node in line.split(',')] for line in f.readlines()]
    #print theNetwork

    return theNetwork

#for each node assign default values
#populate table with default values
def populateNodeTable(): 
    nodeTable = []
    index = 0
    f = open('network.txt', 'r')
    for line in f: 
      networkNode = map(int, line.split(',')) 
      nodeTable.append(Node())

      #print "The previous node is " ,nodeTable[index].previous 
      #print "The distance from source is " ,nodeTable[index].distFromSource
      #print networkNode
      index +=1
    nodeTable[startNode].distFromSource = 0 

    return nodeTable

So, all well and good. However, my next function is giving me an error, and despite me changing variable names in the brackets I can’t work out the problem. Here is the next function code and the error message:

def nearestNeighbour(nodeTable, theNetwork):
     listOfNeighbours = []
     nodeIndex = 0
     for networkNode in nodeTable[currentNode]:
          if networkNode != 0 and networkNode.visited == False: 
             listOfNeighbours.append(nearestNode)
          nodeIndex +=1
     print listOfNeighbours
##     #print node.distFromSource, node.previous, node.visited
##
     return listOfNeighbours

for networkNode in nodeTable[currentNode]:
TypeError: iteration over non-sequence
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:34:39+00:00Added an answer on May 20, 2026 at 2:34 pm

    I think you want nodeTable[node], not node[nodeTable], and similarly with theNetwork[node].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Originally, I was having some issues getting this code to function, but after a
I have changed the Treeview.HideSelection = false; But how do I insure that when
Is there any way to list all the files that have changed between two
I'm actually translating some C++ code (which I know very little about, and have
[EDIT] I changed my code according to the your answers. But now I get
I have some code doing this : var changes = document.getElementsByName(from); for (var c=0;
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);
If I have changed a CSS rule via javascript, do I need to do
When a user have changed something in a form, then clicks on any link

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.