第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在多個 python 列表之間進行交叉檢查以查找重復的 ID

如何在多個 python 列表之間進行交叉檢查以查找重復的 ID

12345678_0001 2022-11-01 16:07:35
我有三個列表,其中包含電子郵件中的電子郵件、標題和文本的請求 ID。我正在嘗試比較電子郵件標題和文本,如果它們重復,則獲取它們的 ID。id1列表以has'title1'和'sampleText1'、id3has'title2'等的方式排序'sampleText2':id = [1, 2, 3, 4, 5, 6]title = ['title1', 'title1', 'title2' 'title3', 'title3', 'title4']text = ['sampleText1', 'sampleText1' 'sampleText2', 'sampleText3', 'sampleText3', 'sampleText4]從上面的列表中,我必須確定哪些是重復的,我想要的輸出是: id = [2, 5]有人可以幫忙嗎?先感謝您!
查看完整描述

3 回答

?
慕田峪9158850

TA貢獻1794條經(jīng)驗 獲得超8個贊

假設(shè)列表大小相同。您需要做的就是遍歷“標題”并比較每個索引處的(嵌套循環(huán))元素。下面的代碼


id = [1, 2, 3, 4, 5, 6]

title = ['title1', 'title1', 'title2', 'title3', 'title3', 'title4']

text = ['sampleText1', 'sampleText1', 'sampleText2', 'sampleText3', 'sampleText3', 'sampleText4']

res = []

for i in range(len(id)):

    for j in range(i+1,len(id)): #i+1 'cause we need to start comparing from the next index

        if title[i] == title[j]:

            res.append(id[j])

            break


print(res)


查看完整回答
反對 回復 2022-11-01
?
繁星點點滴滴

TA貢獻1803條經(jīng)驗 獲得超3個贊

title另一種解決方案是下面的解決方案,其中的順序text無關(guān)緊要:


id = [1, 2, 3, 4, 5, 6]

title = ['title1', 'title1', 'title2', 'title3', 'title3', 'title4']

text = ['sampleText1', 'sampleText1', 'sampleText2', 'sampleText3', 'sampleText3', 'sampleText4']



dupTitles = [] # Titles that are already checked.

dupTexts = [] # Texts that are already checked.

result = [] # Final list of IDs.


for elemId, elemTitle, elemText in zip(id,title,text):

    if elemTitle in dupTitles and elemText in dupTexts:

        result.append(elemId)

    else:

        dupTitles.append(elemTitle)

        dupTexts.append(elemText)


print(result)

結(jié)果將是:


[2, 5]


查看完整回答
反對 回復 2022-11-01
?
一只萌萌小番薯

TA貢獻1795條經(jīng)驗 獲得超7個贊

您可以像這樣使用 for 循環(huán):


id = [1, 2, 3, 4, 5, 6]

title = ['title1', 'title1', 'title2', 'title3', 'title3', 'title4']

text = ['sampleText1', 'sampleText1', 'sampleText2', 'sampleText3', 'sampleText3', 'sampleText4']


result = []


for x in id:

    tmptitle = title[x-1]

    tmptext = text[x-1]

    if x > 0:

        if tmptitle == title[x-2] and tmptext == text[x-2]:

            result.append(x)


print(result)

對于另一個問題,請?zhí)峁┠鸀榻鉀Q問題而編寫的代碼


查看完整回答
反對 回復 2022-11-01
  • 3 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號