Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i fix AttributeError: 'dict_values' object has no attribute 'count'?

here is my code and the text file is here

import networkx as nx
import pylab as plt

webg = nx.read_edgelist('web-graph.txt',create_using=nx.DiGraph(),nodetype=int)
in_degrees = webg.in_degree()
in_values = sorted(set(in_degrees.values()))
in_hist = [in_degrees.values().count(x)for x in in_values]

I want to plot degree distribution web graph how can i change dict to solve?

like image 846
alireza shokrizade Avatar asked Oct 16 '16 11:10

alireza shokrizade


1 Answers

In Python3 dict.values() returns "views" instead of lists:

  • dict methods dict.keys(), dict.items() and dict.values() return "views" instead of lists. https://docs.python.org/3/whatsnew/3.0.html

To convert the "view" into a list, simply wrap in_degrees.values() in a list():

in_hist = [list(in_degrees.values()).count(x) for x in in_values]
like image 94
Tulio Casagrande Avatar answered Sep 28 '22 08:09

Tulio Casagrande