code: def triads_by_type(G):
      """Returns a list of all triads for each triad type in a directed graph.
      There are exactly 16 different types of triads possible. Suppose 1, 2, 3 are three
      nodes, they will be classified as a particular triad type if their connections
      are as follows:
  
      - 003: 1, 2, 3
      - 012: 1 -> 2, 3
      - 102: 1 <-> 2, 3
      - 021D: 1 <- 2 -> 3
      - 021U: 1 -> 2 <- 3
      - 021C: 1 -> 2 -> 3
      - 111D: 1 <-> 2 <- 3
      - 111U: 1 <-> 2 -> 3
      - 030T: 1 -> 2 -> 3, 1 -> 3
      - 030C: 1 <- 2 <- 3, 1 -> 3
      - 201: 1 <-> 2 <-> 3
      - 120D: 1 <- 2 -> 3, 1 <-> 3
      - 120U: 1 -> 2 <- 3, 1 <-> 3
      - 120C: 1 -> 2 -> 3, 1 <-> 3
      - 210: 1 -> 2 <-> 3, 1 <-> 3
      - 300: 1 <-> 2 <-> 3, 1 <-> 3
  
      Refer to the :doc:`example gallery </auto_examples/graph/plot_triad_types>`
      for visual examples of the triad types.
  
      Parameters
      ----------
      G : digraph
         A NetworkX DiGraph
  
      Returns
      -------
      tri_by_type : dict
         Dictionary with triad types as keys and lists of triads as values.
  
      Examples
      --------
      >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 3), (3, 1), (5, 6), (5, 4), (6, 7)])
      >>> dict = nx.triads_by_type(G)
      >>> dict['120C'][0].edges()
      OutEdgeView([(1, 2), (1, 3), (2, 3), (3, 1)])
      >>> dict['012'][0].edges()
      OutEdgeView([(1, 2)])
  
      References
      ----------
      .. [1] Snijders, T. (2012). "Transitivity and triads." University of
          Oxford.
          https://web.archive.org/web/20170830032057/http://www.stats.ox.ac.uk/~snijders/Trans_Triads_ha.pdf
      """
      # num_triads = o * (o - 1) * (o - 2) // 6
      # if num_triads > TRIAD_LIMIT: print(WARNING)
      all_tri = all_triads(G)
      tri_by_type = defaultdict(list)
      for triad in all_tri:
          name = triad_type(triad)
          tri_by_type[name].append(triad)
      return tri_by_type
  
file_path: networkx/networkx/algorithms/triads.py
imports: from collections import defaultdict
  from itertools import combinations, permutations
  import networkx
  from networkx.utils import not_implemented_for, py_random_state
label_desc: Use image node_id 6 for calling a global function with example usage: triads_by_type(G) and returns: tri_by_type