473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How Can I Set First Number on Each Text File Line to be Initial Node in Dijkstra?

Hello,

I am attempting to recreate Dijkstra's algorithm in Python but everything is going wrong.
Here is my code:

Expand|Select|Wrap|Line Numbers
  1. def twoDArray():
  2.     network = []
  3.     sourceNode[]       
  4.     f = open('twoDArray.txt', 'r')
  5.     #network = []  
  6.     for line in f:
  7.                 sourceNode.append(line.split(',') [0])
  8.     line = line = line.rstrip('\n')
  9.     row = line.split(',')
  10.     irow = [int(item) for item in row]
  11.         network.append(irow)
  12.  
  13.     print "Network = "
  14.     print network
  15.  
  16. #def main():
  17.  
  18. if __name__ == "__main__":
  19.     twoDArray()
  20.  
I have a text file containing the distances between nodes that looks similar to this:

Expand|Select|Wrap|Line Numbers
  1. 0,1,2,3,4,5,6,7,8,9,10,11,12
  2. 1,0,3,6,2,7,4,8,6,9,12,10,12
What I am trying to do is to populate a 2D array, which works OK, but then for each line set an initial node so that the distance from the initial node to another node can be calculated, though it isn't working and I don't know what to try next
Feb 22 '11 #1
0 944

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Amy L. | last post by:
Is there a way through .net to read a very large text file (400MB+) backwards line by line. In system.io the filestream class has a "seek" method but the only read method requires you to know how...
4
by: Volker Jobst | last post by:
Hi, Is there a really fast way to read a text file which contains lines of variable length? I'm using the StreamReader to read the file, but this is not as fast as I need it. thanks a lot...
3
by: JenHu | last post by:
Hi, I want read line by line and characters. The characters are fix length text file, no specific delimited method between each fields. The first line is header line, the last line is footer. ...
3
by: Daron | last post by:
I am using this command to import text file: DoCmd.TransferText acImportDelim, str_SpecName, str_TblName, str_FileName, False - The import will always be missing the first line in the text...
5
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
6
by: kimiraikkonen | last post by:
Hi, I want to save all the item content of a listbox line by line into a simple text file then recall them when my project is opened. For example listbox1 contains: That - item1 Group ...
7
by: kashif73 | last post by:
I have a text file , from which I read a single line & display it in my form. How can I read the line number for that particular line, which is being displayed in my form?? Thanks.
6
by: kronus | last post by:
Hi everyone, This is my first time posting to the UNIX form and it might be a strange request, but I believe I have most of the pieces. Here's the overall goal -- I am trying to find the links...
8
by: No Signal X | last post by:
hello i'm having a problem in reading a text file line by line with splitting words, counting the number of lines & words and saving the position of each word i've started with this : public...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.