Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33146
| Date | 2012-11-11 16:49 -0600 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: List comprehension for testing **params |
| References | <50a0258f$0$21241$ba4acef3@reader.news.orange.fr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3564.1352675058.27098.python-list@python.org> (permalink) |
> assert[key for key in required if key in params.keys()] ... > Could you explain why it doesn't work and do you have any idea of how it > could work ? Well, here, if any of the items are found, you get a list that is non-False'ish, so the assert passes. It sounds like you want all() (available as of 2.5) assert all(key in params for key in required) This is modulo any key normalization for "From" vs. "FROM" vs. "from", etc; but should be enough to pass your initial requirements. -tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
List comprehension for testing **params Cantabile <cantabile.03@wanadoo.fr> - 2012-11-11 23:24 +0100
Re: List comprehension for testing **params Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-11 15:56 -0700
Re: List comprehension for testing **params Tim Chase <python.list@tim.thechases.com> - 2012-11-11 16:49 -0600
Re: List comprehension for testing **params Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-11 23:18 +0000
Re: List comprehension for testing **params Tim Chase <python.list@tim.thechases.com> - 2012-11-11 18:21 -0600
Re: List comprehension for testing **params Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-12 07:32 +0000
Re: List comprehension for testing **params Terry Reedy <tjreedy@udel.edu> - 2012-11-11 18:37 -0500
Re: List comprehension for testing **params Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-11 23:41 +0000
Re: List comprehension for testing **params Cantabile <cantabile.03@wanadoo.fr> - 2012-11-12 00:53 +0100
Re: List comprehension for testing **params Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-11-12 11:48 +0100
Re: List comprehension for testing **params Cantabile <cantabile.03@wanadoo.fr> - 2012-11-12 23:25 +0100
csiph-web