去掉两个列表中的公共元素

Boern <[email protected]>
reply-to        [email protected]
to      [email protected]
date    Thu, Jun 19, 2008 at 09:45
subject [CPyUG:55253] 如何把两个列表中的公共元素去掉?

如题,现在如果有 a=[1,2,3] ;b= [2,3,4] ,有没有最简单的方法把 a,b 中共有的 2,3元素去掉,之后 a=[1],b=[4]?

马踏飞燕 二法

马踏飞燕 <[email protected]>

法一

   1 a = list(set(a)-set(b))
   2 b = list(set(b)-set(a))
法二

   1 a = list(set(a) - (set(a) and set(b)))
   2 b= list(set(b) - (set(a) and set(b)))


反馈

创建 by -- ZoomQuiet [2008-06-20 03:10:55]

MiscItems/2008-06-20 (last edited 2009-12-25 07:17:58 by localhost)