Or you could use actual sets:
>>> colors = set(['red', 'green', 'blue', 'orange', 'fuscia', 'black',
'white'])
>>> subset = set(['red', 'green', 'blue', 'purple'])
>>> subset.intersection(colors)
set(['blue', 'green', 'red'])
Of course, this loses your ordering, but it's otherwise far easier to r
Indeed. That's awfully nice and concise.
On Fri, 29 Oct 2010 09:14:06 -0700, Christopher Barker
wrote:
> 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','ora
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
I've been trying to use more list comprehensions recently.
I was just
fleshing something out which brought on my post.
On Fri, 29 Oct 2010
09:15:47 -0400, Henry Olders wrote: When dealing with lists, list
comprehensions are shorter and easier to work with:
l=['red','green','orange','blue','r
On 28 Oct 2010, at 15:21, Dan Ross wrote:
> if x == 'red' or 'green' or 'blue':
>
> if x == 'red' or 'green' or 'blue':
I think your logic might need straightening here, you're saying
if (x == 'red')
or
if 'green'
or
if 'blue'
but I think you mean
if (x == 'red')
Thank you for your help guys.
Zach, I appreciate the explanation. That's what I was looking for.
Dan
Part 3
Description: boundary/apple-mail-7-733662729
___
Pythonmac-SIG maillist - Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pyt
I have attached a copy of the originally-posted Python code and also have
attached an IDLE session based on that code, which seems instructive.
(Copying and pasting the IDLE session into the email message seems to mess
up the indentation.)
But Zachary's suggestions for rewriting the original Python
On Oct 28, 2010, at 11:08 AM, Ronald Oussoren wrote:
On 28 Oct, 2010, at 16:21, Dan Ross wrote:
I don't think this is Mac specific, but I wonder if someone could
explain why these two groups of code behave differently:
[code]
colors = ['red', 'green', 'blue', 'orange', 'fuscia', 'black',
On 28 Oct, 2010, at 16:21, Dan Ross wrote:
> I don't think this is Mac specific, but I wonder if someone could explain why
> these two groups of code behave differently:
>
> [code]
>
> colors = ['red', 'green', 'blue', 'orange', 'fuscia', 'black', 'white']
>
> list_of_matches = []
> for x in
I don't think this is Mac specific, but I wonder if someone could
explain why these two groups of code behave differently:
[code]
colors
= ['red', 'green', 'blue', 'orange', 'fuscia', 'black',
'white']
list_of_matches = []
for x in colors:
if x == 'red' or 'green'
or 'blue':
list_of_matche
10 matches
Mail list logo