#NEWLINE# def set_edge_attributes( G , name , values ) : #NEWLINE# #INDENT# "Sets edge attributes from a given value or dictionary of values.\n\n    Parameters\n    ----------\n    G : NetworkX Graph\n\n    name : string\n       Name of the edge attribute to set.\n\n    values : dict\n       Dictionary of attribute values keyed by edge (tuple). For\n       multigraphs, the tuples must be of the form ``(u, v, key)``,\n       where `u` and `v` are nodes and `key` is the key corresponding to\n       the edge. For non-multigraphs, the keys must be tuples of the\n       form ``(u, v)``.\n\n       If `values` is not a dictionary, then it is treated as a single\n       attribute value that is then applied to every edge in `G`. This\n       means that if you provide a mutable object, like a list, updates\n       to that object will be reflected in the edge attribute for each\n       edge.\n\n    Examples\n    --------\n    After computing some property of the nodes of a graph, you may want\n    to assign a node attribute to store the value of that property for\n    each node::\n\n        >>> G = nx.path_graph(3)\n        >>> bb = nx.edge_betweenness_centrality(G, normalized=False)\n        >>> nx.set_edge_attributes(G, 'betweenness', bb)\n        >>> G.edge[1][2]['betweenness']\n        2.0\n\n    If you provide a list as the third argument, updates to the list\n    will be reflected in the edge attribute for each node::\n\n        >>> labels = []\n        >>> nx.set_edge_attributes(G, 'labels', labels)\n        >>> labels.append('foo')\n        >>> G.edge[0][1]['labels']\n        ['foo']\n        >>> G.edge[1][2]['labels']\n        ['foo']\n\n    " #NEWLINE# if ( not isinstance ( values , dict ) ) : #NEWLINE# #INDENT# if G . is_multigraph ( ) : #NEWLINE# #INDENT# edges = G . edges ( keys = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# edges = G . edges ( ) #NEWLINE# #UNINDENT# values = dict ( zip_longest ( edges , [ ] , fillvalue = values ) ) #NEWLINE# #UNINDENT# if G . is_multigraph ( ) : #NEWLINE# #INDENT# for ( ( u , v , key ) , value ) in values . items ( ) : #NEWLINE# #INDENT# G [ u ] [ v ] [ key ] [ name ] = value #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for ( ( u , v ) , value ) in values . items ( ) : #NEWLINE# #INDENT# G [ u ] [ v ] [ name ] = value