Statement evals as False in my IDE and True elsewhere
Terry Reedy
tjreedy at udel.edu
Fri Jan 31 00:09:19 EST 2014
On 1/30/2014 6:00 PM, CM wrote:
> On Thursday, January 30, 2014 5:25:31 PM UTC-5, Chris Angelico wrote:
>> On Fri, Jan 31, 2014 at 9:04 AM, CM <cmpython at gmail.com> wrote:
>>
>>> fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12']
>>
>>> fake_result = not all(i == '[omitted]' for i in fake_data)
>> Trying to get my head around this. You want to see if all the values
>> in fake_data are '[omitted]' or not? That is to say, if there's
>> anything that isn't '[omitted]'? Not sure that that's a normal thing
>> to be asking, but that's what your code appears to do.
>
> That's what I want, yes. It probably sure isn't a normal thing to be asking, and I wouldn't be surprised if I am approaching it the wrong way. Essentially, if ALL the items in that list are '[omitted]', I must not process the list, but if even one of them is something other than '[omitted]', I need to process it.
>
> If there is a more Pythonic / better way to approach that, I'd like to know it.
not all(x) == any(not x), so...
any(i != '[omitted]' for i in fake_data)
While nothing you import should *ever* mask a builtin, this would also
solve the all problem
--
Terry Jan Reedy
More information about the Python-list
mailing list