![](/img/trans.png)
[英]Python comparing two massive sets of data in the MOST efficient method possible
[英]What is the most efficient way of comparing two sets?
在Python3中,比較兩個Set
elements
(是否具有相同元素)的最省時方法是什么?
例如,我想要一個名為compareSets
的函數,如下所示。 我應該如何編寫代碼以使其以最省時的方式工作?
def compareSets(a, b):
# if (elements are identical)
# return True
# if (elements are not identical)
# return False
pass
要測試兩組是否相等,請使用相等運算符( ==
)。 這是REPL中的一個示例,它利用了可迭代的字符串:
>>> set('a') == set('a')
True
>>> set('a') == set('b')
False
>>> set('a') == set('ab')
False
>>> set('ba') == set('ab') #Shows the sets are order-independent
True
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.