Or you could use actual sets: <br><br>>>> colors = set(['red', 'green', 'blue', 'orange', 'fuscia', 'black', 'white'])<br>>>> subset = set(['red', 'green', 'blue', 'purple'])<br>
>>> subset.intersection(colors)<br>set(['blue', 'green', 'red'])<br><br>Of course, this loses your ordering, but it's otherwise far easier to read than a list comprehension.<br><br>-Chris<br>
<br><div class="gmail_quote">On Fri, Oct 29, 2010 at 9:19 AM, Dan Ross <span dir="ltr"><<a href="mailto:dan@rosspixelworks.com">dan@rosspixelworks.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Indeed. That's awfully nice and concise.<br>
<div class="im"><br>
On Fri, 29 Oct 2010 09:14:06 -0700, Christopher Barker<br>
<<a href="mailto:Chris.Barker@noaa.gov">Chris.Barker@noaa.gov</a>> wrote:<br>
> On 10/29/10 7:56 AM, Dan Ross wrote:<br>
> > I've been trying to use more list comprehensions recently.<br>
><br>
> ahh -- then you want something like:<br>
><br>
> In [15]: colors =<br>
['red','green','blue','orange','fuchsia','black','white']<br>
><br>
> In [16]: subset = ['red','green','blue','purple']<br>
><br>
> In [17]: [c for c in colors if c in subset]<br>
><br>
> Out[17]: ['red', 'green', 'blue']<br>
><br>
><br>
> (so much for one obvious way to do it!)<br>
><br>
> -Chris<br>
</div><div><div></div><div class="h5">_______________________________________________<br>
Pythonmac-SIG maillist - <a href="mailto:Pythonmac-SIG@python.org">Pythonmac-SIG@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/pythonmac-sig" target="_blank">http://mail.python.org/mailman/listinfo/pythonmac-sig</a><br>
unsubscribe: <a href="http://mail.python.org/mailman/options/Pythonmac-SIG" target="_blank">http://mail.python.org/mailman/options/Pythonmac-SIG</a><br>
</div></div></blockquote></div><br>