Thanks everybody for all the answers and explanations.
In the end maybe it is simpler if I use sets for these tests.
Thanks again.
--
http://mail.python.org/mailman/listinfo/python-list
"Mr.SpOOn" wrote in message
news:mailman.492.1258380560.2873.python-l...@python.org...
> In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
> Out[13]: True
For anything more than the simplest cases, you might want use sets.
That might be the correct data type from the start, depending on
whe
On Tue, Nov 17, 2009 at 12:46 AM, Chris Rebert wrote:
> On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho wrote:
> > AND operator has a higher precedence, so you don't need any brackets
> here, I
> > think. But anyway, you have to use it like that. So that's something
> you'll
> > have to fix first.
>
On Mon, Nov 16, 2009 at 6:23 AM, Xavier Ho wrote:
'3' in l and 'no3' in l
> True
>
> AND operator has a higher precedence, so you don't need any brackets here, I
> think. But anyway, you have to use it like that. So that's something you'll
> have to fix first.
Er, you mean lower precedence.
Here I expected to get True in the second case too, so clearly I don't
really get how they work.
You're seeing short-circuit evaluation:
>>> "3" or "4" # true
'3'
>>> '4' or '3' # true
'4'
>>> '4' in l# false
False
>>> '3' or False # true
'3'
>>> '4' or '42' in l # tru
On Tue, Nov 17, 2009 at 12:08 AM, Mr.SpOOn wrote:
> Sorry for replying to myself, but I think I understood why I was wrong.
>
> The correct statement should be something like this:
>
> In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
> Out[13]: True
>
>
Carlo, I'm not sure what that achieves.
On Mon, Nov 16, 2009 at 6:08 AM, Mr.SpOOn wrote:
> Sorry for replying to myself, but I think I understood why I was wrong.
>
> The correct statement should be something like this:
>
> In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
> Out[13]: True
No, you've just run into another misunderstan
On Tue, Nov 17, 2009 at 12:02 AM, Mr.SpOOn wrote:
> Hi,
> I'm trying to use logical operators (or, and) with the "in" statement,
> but I'm having some problems to understand their behavior.
>
Hey Carlo, I think your issue here is mistaking 'in' as a statement. It's
just another logic operator, m
On Mon, Nov 16, 2009 at 6:02 AM, Mr.SpOOn wrote:
> Hi,
> I'm trying to use logical operators (or, and) with the "in" statement,
> but I'm having some problems to understand their behavior.
>
> In [1]: l = ['3', 'no3', 'b3']
>
> In [2]: '3' in l
> Out[2]: True
>
> In [3]: '3' and '4' in l
> Out[3]:
On 02:02 pm, mr.spoo...@gmail.com wrote:
Hi,
I'm trying to use logical operators (or, and) with the "in" statement,
but I'm having some problems to understand their behavior.
"and" and "or" have no particular interaction with "in".
In [1]: l = ['3', 'no3', 'b3']
In [2]: '3' in l
Out[2]: True
Sorry for replying to myself, but I think I understood why I was wrong.
The correct statement should be something like this:
In [13]: ('b3' and '5') in l or ('3' and 'b3') in l
Out[13]: True
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I'm trying to use logical operators (or, and) with the "in" statement,
but I'm having some problems to understand their behavior.
In [1]: l = ['3', 'no3', 'b3']
In [2]: '3' in l
Out[2]: True
In [3]: '3' and '4' in l
Out[3]: False
In [4]: '3' and 'no3' in l
Out[4]: True
This seems to work a
12 matches
Mail list logo