def adjacencyList(): fileName = input("Please enter desired file name") #must know file name to open with open(fileName) as f: #assuming in same directory A = [None] * 200 #empty primary array for line in f: line = line.split() #removing spaces if line: #eliminating blank lines line = [float(i) for i in line] #using float because of rank A.append(line) #adds into (double) array vertex = [] #for vertex IDs for v in range(len(A)): #for number of vertices vertex.append(int(A[v][0])) #entering in IDs adjList = [-1] * 200 #initializing adjacency list for index in range(arrL): #for all indices in list for a in range(len(vertex)): #for all IDs if index == vertex[a]: #if the index matches the ID adjList[index] = A[a] #information for vertex is entered id = adjList[index][0] #just bc is used more than once print("Vertex ",id,":") #begin output of vertex print("rank = 1, out-degree = ",adjList[index][1]) edge = [] #bc may be more than one need array for b in range(1,len(adjList[index])): #for all poss edge values edge.append(int(adjList[index][b])) #creates set print("Edges to ",id,": ",str(edge).strip('[]')) #prints all edges separated by commas
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question