Hello,
I am attempting to recreate Dijkstra's algorithm in Python but everything is going wrong.
Here is my code: - def twoDArray():
-
network = []
-
sourceNode[]
-
f = open('twoDArray.txt', 'r')
-
#network = []
-
for line in f:
-
sourceNode.append(line.split(',') [0])
-
line = line = line.rstrip('\n')
-
row = line.split(',')
-
irow = [int(item) for item in row]
-
network.append(irow)
-
-
print "Network = "
-
print network
-
-
#def main():
-
-
if __name__ == "__main__":
-
twoDArray()
-
I have a text file containing the distances between nodes that looks similar to this: - 0,1,2,3,4,5,6,7,8,9,10,11,12
-
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
0 944 Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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. ...
|
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...
|
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...
|
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)....
|
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 ...
|
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.
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |