Re: [Pythonmac-SIG] If/else vs or

2010-10-29 Thread Chris Weisiger
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

Re: [Pythonmac-SIG] If/else vs or

2010-10-29 Thread Dan Ross
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

Re: [Pythonmac-SIG] If/else vs or

2010-10-29 Thread Christopher Barker
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

Re: [Pythonmac-SIG] If/else vs or

2010-10-29 Thread Dan Ross
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

Re: [Pythonmac-SIG] If/else vs or

2010-10-28 Thread Daniel O'Donovan
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')

Re: [Pythonmac-SIG] If/else vs or

2010-10-28 Thread Dan Ross
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

Re: [Pythonmac-SIG] If/else vs or

2010-10-28 Thread Richard Fuhr
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

Re: [Pythonmac-SIG] If/else vs or

2010-10-28 Thread Zachary Pincus
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',

Re: [Pythonmac-SIG] If/else vs or

2010-10-28 Thread Ronald Oussoren
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

[Pythonmac-SIG] If/else vs or

2010-10-28 Thread Dan Ross
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