[Pythonmac-SIG] If/else vs or
Christopher Barker
Chris.Barker at noaa.gov
Fri Oct 29 18:14:06 CEST 2010
On 10/29/10 7:56 AM, Dan Ross wrote:
> I've been trying to use more list comprehensions recently.
ahh -- then you want something like:
In [15]: colors = ['red','green','blue','orange','fuchsia','black','white']
In [16]: subset = ['red','green','blue','purple']
In [17]: [c for c in colors if c in subset]
Out[17]: ['red', 'green', 'blue']
(so much for one obvious way to do it!)
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Pythonmac-SIG
mailing list