##language:zh #pragma section-numbers off ##含有章节索引导航的 ZPyUG 文章通用模板 <> ## 默许导航,请保留 <> = 去掉两个列表中的公共元素 = {{{ Boern reply-to python-cn@googlegroups.com to python-cn@googlegroups.com date Thu, Jun 19, 2008 at 09:45 subject [CPyUG:55253] 如何把两个列表中的公共元素去掉? }}} ##startInc 如题,现在如果有 a=[1,2,3] ;b= [2,3,4] ,有没有最简单的方法把 a,b 中共有的 2,3元素去掉,之后 a=[1],b=[4]? == 马踏飞燕 二法 == `马踏飞燕 ` 法一:: {{{#!python a = list(set(a)-set(b)) b = list(set(b)-set(a)) }}} 法二:: {{{#!python a = list(set(a) - (set(a) and set(b))) b= list(set(b) - (set(a) and set(b))) }}} ##endInc ---- '''反馈''' 创建 by -- ZoomQuiet [<>]