Count the groups

graph is an adjacency dictionary for a two-way graph; every node is a key, including nodes with no neighbours. Write count_components(graph) that returns how many separate connected groups there are.

count_components({1: [2], 2: [1], 3: [4], 4: [3, 5], 5: [4], 6: []})  ->  3
count_components({})                                                  ->  0

The point is to practise running a search from every unvisited node.

def count_components(graph):
    ...