如何从网络图中获取学位。
list(graph.degree().values())
示例[0,2,4,1,0,3,2,1,4,0,2,0],我只想要像这样的学位。
[0,1,2,3,4]
在python或networkx中有某种功能
答案 0 :(得分:1)
如果您只想在列表中保留唯一元素,
使用set()
mylist = list(graph.degree().values())
unique_elements_list = list(set(mylist))
使用list()
:
mylist = list(graph.degree().values())
unique_elements_list = list()
# iterates all elements in mylist
for element in mylist:
# adds to unique elements list only current
# element is not included.
if element not in unique_elements_list:
unique_elements_list.append(element)