Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65092
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Statement evals as False in my IDE and True elsewhere |
| Date | 2014-01-31 00:09 -0500 |
| References | <a543e1a5-ef00-42b0-96df-5bf9ee8ac74c@googlegroups.com> <mailman.6171.1391121221.18130.python-list@python.org> <5673ebd0-89b6-485c-8ccb-f62bf15f513a@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6193.1391145004.18130.python-list@python.org> (permalink) |
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@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 14:04 -0800
Re: Statement evals as False in my IDE and True elsewhere Peter Otten <__peter__@web.de> - 2014-01-30 23:14 +0100
Re: Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 14:48 -0800
Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 09:55 +1100
Re: Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 15:02 -0800
Re: Statement evals as False in my IDE and True elsewhere Peter Otten <__peter__@web.de> - 2014-01-31 00:08 +0100
Re: Statement evals as False in my IDE and True elsewhere Terry Reedy <tjreedy@udel.edu> - 2014-01-31 00:05 -0500
Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 16:07 +1100
Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 09:25 +1100
Re: Statement evals as False in my IDE and True elsewhere CM <cmpython@gmail.com> - 2014-01-30 15:00 -0800
Re: Statement evals as False in my IDE and True elsewhere Chris Angelico <rosuav@gmail.com> - 2014-01-31 10:25 +1100
Re: Statement evals as False in my IDE and True elsewhere Terry Reedy <tjreedy@udel.edu> - 2014-01-31 00:09 -0500
csiph-web