在多个列表中找到共同值,并绘制图形(Python+ NetWrokx)
我想找到所有列表中存在的数字。有人帮助我如何删除此错误? 代码和屏幕截图以下
import networkx as nx
G = nx.karate_club_graph()
tri=nx.triangles(G)
all_cliques= nx.enumerate_all_cliques(G)
triad_cliques=[x for x in all_cliques if len(x)==3 ]
print(triad_cliques)
cliques = nx.find_cliques(G)
cliques3 = [clq for clq in cliques if 3<=len(clq)<= 3]
print()
elements_in_all = list(set.intersection(*map(set, [cliques,triad_cliques])))
print(elements_in_all)
[错误] [1]:https://i.sstatic.net/5eii0h.png
I would like to find numbers that exist in all the lists.i'm trying but this code giving me unhashable error. anybody else help me how i can remove this error ??
code and screenshot are given below
import networkx as nx
G = nx.karate_club_graph()
tri=nx.triangles(G)
all_cliques= nx.enumerate_all_cliques(G)
triad_cliques=[x for x in all_cliques if len(x)==3 ]
print(triad_cliques)
cliques = nx.find_cliques(G)
cliques3 = [clq for clq in cliques if 3<=len(clq)<= 3]
print()
elements_in_all = list(set.intersection(*map(set, [cliques,triad_cliques])))
print(elements_in_all)
[Error][1]: https://i.sstatic.net/5Ei0H.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为一套无法列出元素。因此,我用3个数字的元组替换了3个数字的列表。我用集团和插入的集团替换了cliques3以打印:
输出:
[[0,1,2],[0,1,3],[0,1,7],[0,1,13],[0,1,17],[0,1,19],[ 0,1,21],[0,2,3],[0,2,7],[0,2,8],[0,2,13],[0,3,7],[0],[0,[0, 3,12],[0,3,13],[0,4,6],[0,4,10],[0,5,6],[0,5,10] 3],[1,2,7],[1,2,13],[1,3,7],[1,3,13],[2,3,7],[2,3,13] ,[2,8,32],[5,6,16],[8,30,32],[8,30,33],[8,32,33],[14,32,33],[ 15,32,33],[18,32,33],[20,32,33],[22,32,33],[23,27,33],[23,29,32] 29,33],[23,32,33],[24,25,31],[26,29,33],[28,31,33],[29,32,33],[30,32, 33],[31,32,33]]
[[0,1,17],[0,1,19],[0,1,21],[0,4,10],[0,4,6],[0,5,5,10],[ 0,5,6],[0,8,2],[0,12,3],[2,32,8],[5,16,6],[33,32,14],[33,[33, 32,15],[33,32,18],[33,32,20],[33,32,22],[33,32,31],[33,26,29] 23],[33,28,31],[24,25,31]]
{(0,5,10),(0,1,19),(0,5,6),(0,4,10),(24,25,31),(0,4,6),(( 0,1,21),(0,1,17)}}
I think that a set cannot take list for element. So I replaced list of 3 numbers by tuple of 3 numbers. I replaced cliques3 by cliques and inserted cliques to print:
Output:
[[0, 1, 2], [0, 1, 3], [0, 1, 7], [0, 1, 13], [0, 1, 17], [0, 1, 19], [0, 1, 21], [0, 2, 3], [0, 2, 7], [0, 2, 8], [0, 2, 13], [0, 3, 7], [0, 3, 12], [0, 3, 13], [0, 4, 6], [0, 4, 10], [0, 5, 6], [0, 5, 10], [1, 2, 3], [1, 2, 7], [1, 2, 13], [1, 3, 7], [1, 3, 13], [2, 3, 7], [2, 3, 13], [2, 8, 32], [5, 6, 16], [8, 30, 32], [8, 30, 33], [8, 32, 33], [14, 32, 33], [15, 32, 33], [18, 32, 33], [20, 32, 33], [22, 32, 33], [23, 27, 33], [23, 29, 32], [23, 29, 33], [23, 32, 33], [24, 25, 31], [26, 29, 33], [28, 31, 33], [29, 32, 33], [30, 32, 33], [31, 32, 33]]
[[0, 1, 17], [0, 1, 19], [0, 1, 21], [0, 4, 10], [0, 4, 6], [0, 5, 10], [0, 5, 6], [0, 8, 2], [0, 12, 3], [2, 32, 8], [5, 16, 6], [33, 32, 14], [33, 32, 15], [33, 32, 18], [33, 32, 20], [33, 32, 22], [33, 32, 31], [33, 26, 29], [33, 27, 23], [33, 28, 31], [24, 25, 31]]
{(0, 5, 10), (0, 1, 19), (0, 5, 6), (0, 4, 10), (24, 25, 31), (0, 4, 6), (0, 1, 21), (0, 1, 17)}