Python Forum
need help with some explanation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with some explanation
#1
http://imgur.com/a/Ijcbi
n = int(input("Enter the number of vertices you want"))
FileName = input("Please input name of file:")
edgeFile = open(FileName)

#empty adj.list
adjList = n*[0]
for i in range(n):
    adjList[i]=[]

#adj.list
for line in edgeFile:
    edgePoint = line.split()
    adjList[int(edgePoint[0])].append(int(edgePoint[1]))
    adjList[int(edgePoint[1])].append(int(edgePoint[0]))

edgeFile.close
print(adjList)
This code was given by lecturer and it works and gives the result : [[1, 2], [0, 2, 3], [1, 0], [1]]
I've been trying to understand why it gives output like that,i know those are the vertices that connects but i just don't know how the table of [[1, 2], [0, 2, 3], [1, 0], [1]] is produced.
Moderator Larz60+: Added code tags. Please use in the future


Reply


Messages In This Thread
need help with some explanation - by vincelim99 - Mar-24-2017, 01:23 AM
RE: need help with some explanation - by zivoni - Mar-24-2017, 09:49 AM
RE: need help with some explanation - by nilamo - Mar-24-2017, 04:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New learner in Python, and need help on the term explanation BaicaiPy 3 1,291 Oct-15-2022, 03:31 PM
Last Post: Yoriz
  Some line code explanation Chrilo06 3 2,086 Feb-24-2022, 06:24 PM
Last Post: deanhystad
  XOR solution explanation needed. omm 7 3,195 Oct-26-2020, 06:30 AM
Last Post: omm
  While statement explanation alkhufu2 3 2,393 Sep-02-2020, 05:46 PM
Last Post: alkhufu2
  Output explanation AmanTripathi 2 2,801 Feb-14-2018, 03:03 PM
Last Post: AmanTripathi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020