寫功能commonElements(T1,T2),其在2元組取作爲參數,並返回包含了在兩個元組找到的元素的排序元組。如何比較兩個元組?
例子
>>> commonElements((1, 2, 3), (2, 5, 1))
(1, 2)
>>> commonElements((1, 2, 3, 'p', 'n'), (2, 5 ,1, 'p'))
(1, 2, 'p')
>>> commonElements((1, 3, 'p', 'n'), ('a', 2 , 5, 1, 'p'))
(1, 'p')
我想兩個元
def commonElements(t1,t2):
if t1 in t2:
return t1
你嘗試過什麼?的[元組比較] – vaultah 2014-11-23 11:45:29
可能重複(http://stackoverflow.com/questions/4405122/tuple-comparison) – Aleksandar 2014-11-23 11:49:38
是,但它給我的錯誤 – 2014-11-23 11:50:05