Python Forum
need help with some explanation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help with some explanation
#2
Before your for loop. adjList is initialized as [[], [], [], []]. In every pass of a loop one line is read from file, converted to a pair of ints and "processed".

First line is 0 1, that means there is an edge connecting vertex 0 with vertex 1, so 1 is appended to adj[0] list (to note that vertex 0 is connected to vertex 1), and 0 is appended to adj[1] list (again, to note that 1 is connected to 0). So after first run of loop block adjList is [[1], [0], [], []].

In second run edge 2 1 is added, so adjList becomes [[1], [0, 2], [1], []]. In remaining two runs edges 0 2 and 1 3 are added, so when for loop ends, adjList is [[1, 2], [0, 2, 3], [1, 0], [1]]

And , "need help with some explanation" is a terrible thread title, title actually saying something would be much better - for example "making graph from file" or "how edges convert to a list".
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,319 Oct-15-2022, 03:31 PM
Last Post: Yoriz
  Some line code explanation Chrilo06 3 2,147 Feb-24-2022, 06:24 PM
Last Post: deanhystad
  XOR solution explanation needed. omm 7 3,263 Oct-26-2020, 06:30 AM
Last Post: omm
  While statement explanation alkhufu2 3 2,412 Sep-02-2020, 05:46 PM
Last Post: alkhufu2
  Output explanation AmanTripathi 2 2,846 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