簡體   English   中英

比較兩個元組列表,然后返回true / false

[英]compare two tuple lists and then return true/false

lst = [('NOUN', 'chip'), ('NOUN', 'potato'), ('potato', 'chip')]

permute_lst = [('NOUN', 'chip'), ('potato', 'chip'), ('potato', 'bbq'), ('NOUN', 'potato'), ('potato', 'crisp')]

我想在自定義函數中比較這兩個元組列表,以返回布爾值列表。 我當前的代碼:

def get_tf(lst):
  tf_list = []
  for lookup in permute_lst:
    if set(lst) == set(lookup):
        tf_list.append(True)
    else:
        tf_list.append(False)
  return tf_list

結果tf_list=[False, False, False, False, False]

我的預期結果是:

tf_list = [True, True, False, True, False]

使用列表permute_list ,該列表permute_list僅檢查每個permute_list項目是否在參考列表中:

return [pair in lst for pair in permute_lst]

輸出:

[True, True, False, True, False]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM