Module Expr Str Assign NameStore ListLoad Str Str Str Str Import alias identifier ImportFrom alias alias alias ImportFrom alias FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam defaults Str Str NameLoad Str body Expr Str For NameStore Call NameLoad NameLoad NameLoad NameLoad body AugAssignAdd NameStore Str Expr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr NameLoad decorator_list Call NameLoad Num keyword Str FunctionDef arguments args NameParam NameParam NameParam defaults Str NameLoad body Expr Str TryExcept body Assign NameStore ListComp NameLoad comprehension TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr CompareEq SubscriptLoad NameLoad Index Str Num handlers ExceptHandler body Raise Call NameLoad Str If BoolOpOr CompareIs NameLoad NameLoad CompareIs NameLoad NameLoad body For NameStore NameLoad body For NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad body Expr Yield Call AttributeLoad NameLoad attr Call NameLoad NameLoad NameLoad orelse For NameStore NameLoad body For TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr NameLoad keyword NameLoad body Assign NameStore ListLoad NameLoad NameLoad TryExcept body Expr Call AttributeLoad NameLoad attr GeneratorExp SubscriptLoad NameLoad Index NameLoad comprehension NameStore NameLoad handlers ExceptHandler type NameLoad body Pass Expr Yield Call AttributeLoad NameLoad attr Call NameLoad NameLoad NameLoad decorator_list Call NameLoad Str FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam defaults Str NameLoad NameLoad NameLoad NameLoad body Expr Str ImportFrom alias Assign NameStore Call NameLoad NameLoad For NameStore NameLoad body Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareGtE NameLoad Num body Assign NameStore SubscriptLoad NameLoad Slice NameLoad If UnaryOpNot Call NameLoad NameLoad body Continue Assign NameStore Call AttributeLoad Call AttributeLoad NameLoad attr attr NameLoad If CompareLt Call NameLoad NameLoad Num body Continue Assign NameStore Call AttributeLoad NameLoad attr Num Assign NameStore Call AttributeLoad NameLoad attr Num Assign NameStore NameLoad If CompareIsNot NameLoad NameLoad body TryExcept body Assign NameStore Call NameLoad NameLoad Assign NameStore Call NameLoad NameLoad handlers ExceptHandler body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad NameLoad If BoolOpOr CompareEq Call NameLoad NameLoad Num CompareIs NameLoad NameLoad body Assign NameStore Dict orelse If CompareIs NameLoad NameLoad body TryExcept body Assign NameStore Call NameLoad Call NameLoad Call AttributeLoad Str attr NameLoad handlers ExceptHandler body Raise Call NameLoad BinOpMod Str NameLoad orelse If CompareNotEq Call NameLoad NameLoad Call NameLoad NameLoad body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad Assign NameStore Dict For TupleStore TupleStore NameStore NameStore NameStore Call NameLoad NameLoad NameLoad body TryExcept body Assign NameStore Call NameLoad NameLoad handlers ExceptHandler body Raise Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr Dict NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad keyword Num Expr Call AttributeLoad NameLoad attr NameLoad keyword Num Expr Call AttributeLoad NameLoad attr NameLoad NameLoad keyword NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam NameParam NameParam NameParam NameParam defaults Str NameLoad NameLoad NameLoad NameLoad NameLoad Str body Expr Str Assign NameStore GeneratorExp Call AttributeLoad NameLoad attr NameLoad comprehension NameStore NameLoad Return Call NameLoad NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad keyword NameLoad decorator_list Call NameLoad Num keyword Str
N/A N/A 
**********
Bipartite Edge Lists
**********
Read and write NetworkX graphs as bipartite edge lists.

Format
------
You can read or write three formats of edge lists with these functions.

Node pairs with no data::

 1 2

Python dictionary as data::

 1 2 {'weight':7, 'color':'green'}

Arbitrary data::

 1 2 7 green

For each edge (u, v) the node u is assigned to part 0 and the node v to part 1.
 N/A __all__ N/A generate_edgelist write_edgelist parse_edgelist read_edgelist N/A networkx nx networkx.utils open_file make_str not_implemented_for networkx.convert _prep_create_using write_edgelist N/A N/A G path comments delimiter data encoding N/A # True utf-8 N/A N/A Write a bipartite graph as a list of edges.

    Parameters
    ----------
    G : Graph
       A NetworkX bipartite graph
    path : file or string
       File or filename to write. If a file is provided, it must be
       opened in 'wb' mode. Filenames ending in .gz or .bz2 will be compressed.
    comments : string, optional
       The character used to indicate the start of a comment
    delimiter : string, optional
       The string used to separate values.  The default is whitespace.
    data : bool or list, optional
       If False write no edge data.
       If True write a string representation of the edge data dictionary..
       If a list (or other iterable) is provided, write the  keys specified
       in the list.
    encoding: string, optional
       Specify which encoding to use when writing file.

    Examples
    --------
    >>> G=nx.path_graph(4)
    >>> G.add_nodes_from([0,2], bipartite=0)
    >>> G.add_nodes_from([1,3], bipartite=1)
    >>> nx.write_edgelist(G, "test.edgelist")
    >>> fh=open("test.edgelist",'wb')
    >>> nx.write_edgelist(G, fh)
    >>> nx.write_edgelist(G, "test.edgelist.gz")
    >>> nx.write_edgelist(G, "test.edgelist.gz", data=False)

    >>> G=nx.Graph()
    >>> G.add_edge(1,2,weight=7,color='red')
    >>> nx.write_edgelist(G,'test.edgelist',data=False)
    >>> nx.write_edgelist(G,'test.edgelist',data=['color'])
    >>> nx.write_edgelist(G,'test.edgelist',data=['color','weight'])

    See Also
    --------
    write_edgelist()
    generate_edgelist()
     N/A line N/A generate_edgelist G delimiter data N/A N/A line N/A N/A N/A path write N/A N/A line encode encoding N/A N/A open_file 1 mode wb generate_edgelist N/A N/A G delimiter data N/A True N/A N/A Generate a single line of the bipartite graph G in edge list format.

    Parameters
    ----------
    G : NetworkX graph
       The graph is assumed to have node attribute `part` set to 0,1 representing
       the two graph parts

    delimiter : string, optional
       Separator for node labels

    data : bool or list of keys
       If False generate no edge data.  If True use a dictionary
       representation of edge data.  If a list of keys use a list of data
       values corresponding to the keys.

    Returns
    -------
    lines : string
        Lines of data in adjlist format.

    Examples
    --------
    >>> from networkx.algorithms import bipartite
    >>> G = nx.path_graph(4)
    >>> G.add_nodes_from([0,2], bipartite=0)
    >>> G.add_nodes_from([1,3], bipartite=1)
    >>> G[1][2]['weight'] = 3
    >>> G[2][3]['capacity'] = 12
    >>> for line in bipartite.generate_edgelist(G, data=False):
    ...     print(line)
    0 1
    2 1
    2 3

    >>> for line in bipartite.generate_edgelist(G):
    ...     print(line)
    0 1 {}
    2 1 {'weight': 3}
    2 3 {'capacity': 12}

    >>> for line in bipartite.generate_edgelist(G,data=['weight']):
    ...     print(line)
    0 1
    2 1 3
    2 3
     N/A N/A N/A part0 N/A n N/A N/A n d N/A N/A N/A G node items N/A N/A d N/A bipartite 0 N/A N/A N/A N/A N/A AttributeError Missing node attribute `bipartite` N/A N/A N/A data True N/A data False N/A N/A n part0 N/A N/A e N/A N/A G edges n data data N/A N/A N/A N/A N/A delimiter join N/A map make_str e N/A N/A n part0 N/A N/A N/A u v d N/A N/A G edges n data True N/A N/A e N/A u v N/A N/A N/A N/A N/A e extend N/A N/A d N/A k N/A k data N/A N/A N/A KeyError N/A N/A N/A N/A N/A N/A delimiter join N/A map make_str e N/A N/A not_implemented_for directed parse_edgelist N/A N/A lines comments delimiter create_using nodetype data N/A # None None None True N/A N/A Parse lines of an edge list representation of a bipartite graph.

    Parameters
    ----------
    lines : list or iterator of strings
        Input data in edgelist format
    comments : string, optional
       Marker for comment lines
    delimiter : string, optional
       Separator for node labels
    create_using: NetworkX graph container, optional
       Use given NetworkX graph for holding nodes or edges.
    nodetype : Python type, optional
       Convert nodes to this type.
    data : bool or list of (label,type) tuples
       If False generate no edge data or if True use a dictionary
       representation of edge data or a list tuples specifying dictionary
       key names and types for edge data.

    Returns
    -------
    G: NetworkX Graph
        The bipartite graph corresponding to lines

    Examples
    --------
    Edgelist with no data:

    >>> from networkx.algorithms import bipartite
    >>> lines = ["1 2",
    ...          "2 3",
    ...          "3 4"]
    >>> G = bipartite.parse_edgelist(lines, nodetype = int)
    >>> sorted(G.nodes())
    [1, 2, 3, 4]
    >>> sorted(G.nodes(data=True))
    [(1, {'bipartite': 0}), (2, {'bipartite': 0}), (3, {'bipartite': 0}), (4, {'bipartite': 1})]
    >>> sorted(G.edges())
    [(1, 2), (2, 3), (3, 4)]

    Edgelist with data in Python dictionary representation:

    >>> lines = ["1 2 {'weight':3}",
    ...          "2 3 {'weight':27}",
    ...          "3 4 {'weight':3.0}"]
    >>> G = bipartite.parse_edgelist(lines, nodetype = int)
    >>> sorted(G.nodes())
    [1, 2, 3, 4]
    >>> sorted(G.edges(data = True))
    [(1, 2, {'weight': 3}), (2, 3, {'weight': 27}), (3, 4, {'weight': 3.0})]

    Edgelist with data in a list:

    >>> lines = ["1 2 3",
    ...          "2 3 27",
    ...          "3 4 3.0"]
    >>> G = bipartite.parse_edgelist(lines, nodetype = int, data=(('weight',float),))
    >>> sorted(G.nodes())
    [1, 2, 3, 4]
    >>> sorted(G.edges(data = True))
    [(1, 2, {'weight': 3.0}), (2, 3, {'weight': 27.0}), (3, 4, {'weight': 3.0})]

    See Also
    --------
     ast literal_eval N/A G N/A _prep_create_using create_using N/A line lines N/A N/A p N/A N/A line find comments N/A N/A p 0 N/A N/A line N/A line N/A p N/A N/A N/A len line N/A N/A N/A s N/A N/A N/A N/A line strip split delimiter N/A N/A N/A len s 2 N/A N/A N/A u N/A N/A s pop 0 N/A v N/A N/A s pop 0 N/A d s N/A N/A nodetype None N/A N/A N/A N/A u N/A nodetype u N/A v N/A nodetype v N/A N/A N/A N/A N/A TypeError N/A Failed to convert nodes %s,%s to type %s. N/A u v nodetype N/A N/A N/A N/A len d 0 N/A data False N/A N/A edgedata N/A N/A N/A N/A data True N/A N/A N/A N/A edgedata N/A dict N/A literal_eval N/A N/A join d N/A N/A N/A N/A N/A TypeError N/A Failed to convert edge data (%s) to dictionary. d N/A N/A N/A N/A len d N/A len data N/A N/A N/A IndexError N/A Edge data %s and data_keys %s are not the same length N/A d data N/A edgedata N/A N/A N/A N/A edge_key edge_type edge_value N/A zip data d N/A N/A N/A N/A edge_value N/A edge_type edge_value N/A N/A N/A N/A N/A TypeError N/A Failed to convert %s data %s to type %s. N/A edge_key edge_value edge_type N/A N/A N/A edgedata update N/A edge_key edge_value N/A N/A N/A G add_node u bipartite 0 N/A N/A N/A G add_node v bipartite 1 N/A N/A N/A G add_edge u v attr_dict edgedata N/A G N/A read_edgelist N/A N/A path comments delimiter create_using nodetype data edgetype encoding N/A # None None None True None utf-8 N/A N/A Read a bipartite graph from a list of edges.

    Parameters
    ----------
    path : file or string
       File or filename to read. If a file is provided, it must be
       opened in 'rb' mode.
       Filenames ending in .gz or .bz2 will be uncompressed.
    comments : string, optional
       The character used to indicate the start of a comment.
    delimiter : string, optional
       The string used to separate values.  The default is whitespace.
    create_using : Graph container, optional,
       Use specified container to build graph.  The default is networkx.Graph,
       an undirected graph.
    nodetype : int, float, str, Python type, optional
       Convert node data from strings to specified type
    data : bool or list of (label,type) tuples
       Tuples specifying dictionary key names and types for edge data
    edgetype : int, float, str, Python type, optional OBSOLETE
       Convert edge data from strings to specified type and use as 'weight'
    encoding: string, optional
       Specify which encoding to use when reading file.

    Returns
    -------
    G : graph
       A networkx Graph or other type specified with create_using

    Examples
    --------
    >>> from networkx.algorithms import bipartite
    >>> G = nx.path_graph(4)
    >>> G.add_nodes_from([0,2], bipartite=0)
    >>> G.add_nodes_from([1,3], bipartite=1)
    >>> bipartite.write_edgelist(G, "test.edgelist")
    >>> G = bipartite.read_edgelist("test.edgelist")

    >>> fh = open("test.edgelist", 'rb')
    >>> G = bipartite.read_edgelist(fh)
    >>> fh.close()

    >>> G=bipartite.read_edgelist("test.edgelist", nodetype=int)

    Edgelist with data in a list:

    >>> textline = '1 2 3'
    >>> fh = open('test.edgelist','w')
    >>> d = fh.write(textline)
    >>> fh.close()
    >>> G = bipartite.read_edgelist('test.edgelist', nodetype=int, data=(('weight',float),))
    >>> list(G)
    [1, 2]
    >>> list(G.edges(data=True))
    [(1, 2, {'weight': 3.0})]

    See parse_edgelist() for more examples of formatting.

    See Also
    --------
    parse_edgelist

    Notes
    -----
    Since nodes must be hashable, the function nodetype must return hashable
    types (e.g. int, float, str, frozenset - or tuples of those, etc.)
     N/A lines N/A N/A N/A line decode encoding N/A line path N/A N/A parse_edgelist lines comments comments delimiter delimiter create_using create_using nodetype nodetype data data N/A N/A open_file 0 mode rb