code: def reciprocity(G, nodes=None):
      r"""Compute the reciprocity in a directed graph.
  
      The reciprocity of a directed graph is defined as the ratio
      of the number of edges pointing in both directions to the total
      number of edges in the graph.
      Formally, $r = |{(u,v) \in G|(v,u) \in G}| / |{(u,v) \in G}|$.
  
      The reciprocity of a single node u is defined similarly,
      it is the ratio of the number of edges in both directions to
      the total number of edges attached to node u.
  
      Parameters
      ----------
      G : graph
         A networkx directed graph
      nodes : container of nodes, optional (default=whole graph)
         Compute reciprocity for nodes in this container.
  
      Returns
      -------
      out : dictionary
         Reciprocity keyed by node label.
  
      Notes
      -----
      The reciprocity is not defined for isolated nodes.
      In such cases this function will return None.
  
      """
      # If `nodes` is not specified, calculate the reciprocity of the graph.
      if nodes is None:
          return overall_reciprocity(G)
  
      # If `nodes` represents a single node in the graph, return only its
      # reciprocity.
      if nodes in G:
          reciprocity = next(_reciprocity_iter(G, nodes))[1]
          if reciprocity is None:
              raise NetworkXError("Not defined for isolated nodes.")
          else:
              return reciprocity
  
      # Otherwise, `nodes` represents an iterable of nodes, so return a
      # dictionary mapping node to its reciprocity.
      return dict(_reciprocity_iter(G, nodes))
  
imports: import networkx
  from networkx import NetworkXError
  from ..utils import not_implemented_for
label_desc: Use image node_id 1 for calling a global function with example usage: reciprocity(G, nodes) and returns: dict, overall_reciprocity, reciprocity