0

How to display the progress of execution of a code with library functions?

import networkx as nx
graph=nx.erdos_renyi_graph(100000,.2)

visited = set() # Set to keep track of visited nodes of graph.

def dfs(visited, graph, node):  #function for dfs 
    if node not in visited:
        print (node)
        visited.add(node)
        for neighbour in graph[node]:
            dfs(visited, graph, neighbour)

print("Following is the Depth-First Search")
dfs(visited, graph, '5000')
coms=nx.connected_components(graph)
AHQ
  • 33
  • 6

1 Answers1

1

As mentioned in the comments, use tqdm:

from tqdm import tqdm
for i in tqdm(range(10)):
  print(i, end = '')

Output:

100%|██████████| 10/10 [00:00<00:00, 26181.67it/s] 0123456789
  • Hi Keivan, this sort of question is often a duplicate, please search for possibles duplicates first and cite them in a comment on the question. Rather than answering them; duplicates typically get closed quickly so you don't get any rep for answering them. – smci Nov 04 '21 at 00:46
  • where should i use this code? – AHQ Nov 04 '21 at 05:54