import random as rand

# generate data: undirected graph
node_count = 20
soft_max = 5

data = {}
for i in range(node_count):
    data[i] = []
for key, value in data.items():
    for i in range(rand.randint(1, soft_max)):
        node = rand.randint(0, node_count - 1)
        if node != key and node not in value:
            value.append(node)
            data[node].append(key)
print(data)

# algorithm
discovered = {key: False for key in data.keys()}
in_progress = []
start = next(iter(data.keys()))  # start with any element

discovered[start] = True
in_progress.insert(0, start)
while in_progress:
    vertex = in_progress.pop()
    print(vertex)  # do something here
    for neighbour in data[vertex]:
        if not discovered[neighbour]:
            discovered[neighbour] = True
            in_progress.insert(0, neighbour)
