[Python] "TypeError: '>' not supported between instances of 'dict' and 'dict'" when trying to...

Discussão em 'Python' iniciado por Stack, Abril 28, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with networkx and dictionaries:

    print("number of nodes %d" % G.number_of_nodes())
    print("number of edges %d" % G.number_of_edges())
    print("Graph is connected?: %s" % nx.is_connected(G))
    print("Number of connected components: %s" % nx.number_connected_components(G))
    print("Size of connected componnents: %s" % [len(cc) for cc in nx.connected_components(G)])
    print("Network Analysis will be performed on the largest cc from now on")
    largest_cc = max(nx.connected_component_subgraphs(G), key=len)

    dict_communities={}
    num_communities=max([y for x,y in largest_cc.nodes(data=True)]).values()[0]
    for i in range (1,num_communities+1):
    dict_communities = [x for x,y in largest_cc.nodes(data=True) if y['community']==i]


    But I get this error:

    TypeError Traceback (most recent call last)
    <ipython-input-12-fd6e5cb0ddb5> in <module>
    1 dict_communities={}
    ----> 2 num_communities=max([y for x,y in largest_cc.nodes(data=True)])[0]
    3 for i in range (1,num_communities+1):
    4 dict_communities = [x for x,y in largest_cc.nodes(data=True) if y['community']==i]

    TypeError: '>' not supported between instances of 'dict' and 'dict'


    What is the problem in my code?

    Continue reading...

Compartilhe esta Página