code: def set_node_attributes(G, values, name=None):
      
      # Set node attributes based on type of `values`
      if name is not None:  # `values` must not be a dict of dict
          try:  # `values` is a dict
              for n, v in values.items():
                  try:
                      G.node[n][name] = values[n]
                  except KeyError:
                      pass
          except AttributeError:  # `values` is a constant
              for n in G:
                  G.node[n][name] = values
      else:  # `values` must be dict of dict
          for n, d in values.items():
              try:
                  G.node[n].update(d)
              except KeyError:
                  pass
docs: Set node attributes from dictionary of nodes and values
  
          Parameters
          ----------
          G : DyNetx Graph
  
          name : string
             Attribute name
  
          values: dict
             Dictionary of attribute values keyed by node. If `values` is not a
             dictionary, then it is treated as a single attribute value that is then
             applied to every node in `G`.