Python:从一个列表中删除每个

2024-03-28 12:31:12 发布

您现在位置:Python中文网/ 问答频道 /正文

假设每个帐户id有两个列表(下表)。我想删除列表1(competitor\u old)中出现的、列表2(competitor\u new)中也出现的元素。每行基本L2 - L1。你知道吗

因此,从下表中,我将有一个新列(competitor\u new\u unique),第一行的a值是c,d

      account_id competitor_old competitor_new 
          234241            a,b        a,b,c,d
           53266              h            h,s
          342536              j              j
          325632              s          s,g,e
          324346              f              f

期望结果

 account_id competitor_old competitor_new competitor_new_unique
      234241            a,b        a,b,c,d                   c,d
       53266              h            h,s                     s
      342536              j              j
      325632              s          s,g,e                   g,e
      324346              f              f

我的大部分努力都可以从另一个岗位上获得。Remove all the elements that occur in one list from another

谢谢你的意见。你知道吗


Tags: theid元素l1列表new帐户account