如何檢查列表中的某個元素是否存在於另一個列表中?是否將它追加到另一個列表中。如何獲取所有值在列表中?如何檢查列表中的某個元素是否存在於另一個列表
common=[]
def findCommon(interActor,interActor1):
for a in interActor:
if a in interActor1:
common.append(a)
return common
interActor=['Rishi Kapoor','kalkidan','Aishwarya']
interActor1=['Aishwarya','Suman Ranganathan','Rishi Kapoor']
什麼不起作用? – ppperry
你需要在函數內部放置'common'初始化。然後在調用它時將函數結果分配給一個變量。 – Barmar