Can I search a list for a range of values?

Ian Kelly ian.g.kelly at gmail.com
Fri Oct 14 18:58:42 EDT 2011


On Fri, Oct 14, 2011 at 4:48 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Oct 15, 2011 at 9:30 AM, Tim Chase
> <python.list at tim.thechases.com> wrote:
>> The double-if is new to me.  I thought it was an error when I first saw it,
>> but it seems to be legit syntax (or at least one that 2.7 tolerates,
>> intentionally or otherwise...).  I think I'd make it clearer with either
>>
>>
>
> Yeah, it's legal because you can nest fors and ifs in a list comp.
> Stylistic difference, I used "if" instead of "and" because there's no
> way that it could be a bitwise and. (It's a cross-language safety net
> that I sometimes use.) Although the 10<=i<=20 option is definitely
> superior to both.

At least in Python, there is no way that "and" could be a bitwise and
either, since it cannot be overloaded.



More information about the Python-list mailing list