我该如何修复AttributeError:'dict_values'对象没有属性'count'? [英] how can i fix AttributeError: 'dict_values' object has no attribute 'count'?
本文介绍了我该如何修复AttributeError:'dict_values'对象没有属性'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?
推荐答案
在Python3中,dict.values()
返回视图"而不是列表:
In Python3 dict.values()
returns "views" instead of lists:
- dict方法dict.keys(),dict.items()和dict.values()返回视图"而不是列表. https://docs.python.org/3/whatsnew/3.0.html
- dict methods dict.keys(), dict.items() and dict.values() return "views" instead of lists. https://docs.python.org/3/whatsnew/3.0.html
要将视图"转换为列表,只需将in_degrees.values()
包裹在list()
中:
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]
这篇关于我该如何修复AttributeError:'dict_values'对象没有属性'count'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文