<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_graph(g, cutoff=7.0, min_kihs=2):
 """ Get subgraph formed from edges that have max_kh_distance < cutoff. Parameters g : MultiDiGraph representing KIHs g is the output from graph_from_protein cutoff : float Socket cutoff in Angstroms. Default is 7.0. min_kihs : int Minimum number of KIHs shared between all pairs of connected nodes in the graph. Returns ------- networkx.MultiDigraph subgraph formed from edges that have max_kh_distance < cutoff. """

        edge_list = [e for e in g.edges(keys=True, data=True) if e[3]['kih'].max_kh_distance <= cutoff]
        if min_kihs > 0:
            c = Counter([(e[0], e[1]) for e in edge_list])
            # list of nodes that share > min_kihs edges with at least one other node.
            node_list = set(list(itertools.chain.from_iterable([k for k, v in c.items() if v > min_kihs])))
            edge_list = [e for e in edge_list if (e[0] in node_list) and (e[1] in node_list)]
        return networkx.MultiDiGraph(edge_list)