Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!.POSTED!not-for-mail From: TheSaint Newsgroups: comp.lang.python Subject: Re: Converting a set into list Followup-To: comp.lang.python Date: Sun, 15 May 2011 23:56:58 +0800 Organization: Aioe.org NNTP Server Lines: 13 Message-ID: References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> <34fc571c-f382-405d-94b1-0a673da5f46b@t16g2000vbi.googlegroups.com> NNTP-Posting-Host: siC7c5Xztm1kk7c9nGVDuQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.4.11 X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5430 SigmundV wrote: > I think the OP wants to find the intersection of two lists. > list(set(list1) & set(list2)) is indeed one way to achieve this. [i > for i in list1 if i in list2] is another one Exactly. I was confused on that I wasn't able to have a list in return. The set intersection is the smartest result better than a "for" loop or a comprehension list. Infact the operatin loops are compiled into python, therfore they are the fastest. -- goto /dev/null