“无向"元组比较 [英] "Undirected" tuple comparison

查看:21
本文介绍了“无向"元组比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用 python 处理一个无向图,其中边由元组表示(A 和 B 之间的边由 (A,B) 或 (B,A) 表示).我想知道是否有一个元组操作可以像这样执行元组的无向比较:

I am currently working on an undirected graph in python, where the edges are represented by tuples (edge between A and B is represented by either (A,B) or (B,A)). I was wondering whether there is a tuple operation that performs an undirected comparison of tuples like this:

exp1 = undirected_comp((A,B), (B,A))    #exp1 should evaluate to True
exp2 = undirected_comp((A,B), (A,C))    #exp2 should evaluate to False

推荐答案

不完全是,但总的来说,你可以用

not exactly, but in general, you can do this kind of comparison with

set (A,B) == set (B, A)

这篇关于“无向"元组比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆