Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78633
| References | (6 earlier) <m0jm43$pee$1@reader1.panix.com> <gcb0gb-d2u.ln1@chris.zbmc.eu> <CALwzid=zLF1bUcJ9U31YJJjQ4gRTjE2NGFe8Pv5FwgprpazrGA@mail.gmail.com> <mailman.14564.1412280412.18130.python-list@python.org> <542ddce8$0$12985$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2014-10-03 12:44 +1000 |
| Subject | Re: How to show a dictionary sorted on a value within its data? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14568.1412304280.18130.python-list@python.org> (permalink) |
On Fri, Oct 3, 2014 at 9:16 AM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: >> Anyway, pylint doesn't complain about a bare use of lambda, but it >> does complain about a map applied to a lambda or a filter applied to a >> lambda. Pylint says they could be replaced by a list comprehension, >> with the warning "deprecated-lambda". > > The warning name is misleading, lambda is not deprecated. But stylistically, > many people prefer to use a generator expression in place of map or filter: > > # instead of this > map(lambda x: 2*x+1, values) > > # use this > (2*x+1 for x in values) > > # instead of this > filter(lambda x: x > 23, values) > > # use this > (x for x in values if x > 23) Don't forget that your equivalencies are based on the Py3 map/filter, which return non-list iterables. There's no really convenient equivalent to the map() usage of "call this function with each of these args, and discard the return values", as it looks very odd to do a list comp for nothing: [print(x) for x in list_of_strings] Short of borrowing Pike's automap syntax: print(list_of_strings[*]) there's really not much that's better than the original map() call. On the other hand, there aren't actually all that many times when I've needed to do this, and the simple for loop generally suffices: for x in list_of_strings: print(x) So it's not a huge deal. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 10:58 +0100
Re: How to show a dictionary sorted on a value within its data? Peter Otten <__peter__@web.de> - 2014-10-01 12:24 +0200
Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 11:45 +0100
Re: How to show a dictionary sorted on a value within its data? Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-01 06:56 -0400
Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 13:16 +0100
Re: How to show a dictionary sorted on a value within its data? Peter Otten <__peter__@web.de> - 2014-10-01 13:12 +0200
Re: How to show a dictionary sorted on a value within its data? Travis Griggs <travisgriggs@gmail.com> - 2014-10-01 21:57 -0700
Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-02 10:40 +0100
Re: How to show a dictionary sorted on a value within its data? Marko Rauhamaa <marko@pacujo.net> - 2014-10-02 14:17 +0300
Re: How to show a dictionary sorted on a value within its data? Rustom Mody <rustompmody@gmail.com> - 2014-10-02 10:46 -0700
Re: How to show a dictionary sorted on a value within its data? Grant Edwards <invalid@invalid.invalid> - 2014-10-02 14:05 +0000
Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-02 17:33 +0100
Re: How to show a dictionary sorted on a value within its data? Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-02 13:15 -0600
Re: How to show a dictionary sorted on a value within its data? Grant Edwards <invalid@invalid.invalid> - 2014-10-02 19:36 +0000
Re: How to show a dictionary sorted on a value within its data? Dan Stromberg <drsalists@gmail.com> - 2014-10-02 13:06 -0700
Re: How to show a dictionary sorted on a value within its data? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-03 09:16 +1000
Re: How to show a dictionary sorted on a value within its data? Chris Angelico <rosuav@gmail.com> - 2014-10-03 12:44 +1000
Re: How to show a dictionary sorted on a value within its data? Steven D'Aprano <steve@pearwood.info> - 2014-10-03 07:55 +0000
Re: How to show a dictionary sorted on a value within its data? Chris Angelico <rosuav@gmail.com> - 2014-10-03 18:09 +1000
Re: How to show a dictionary sorted on a value within its data? Chris Angelico <rosuav@gmail.com> - 2014-10-03 07:01 +1000
Re: How to show a dictionary sorted on a value within its data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-01 11:27 +0100
Re: How to show a dictionary sorted on a value within its data? Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-01 06:37 -0400
Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 13:19 +0100
csiph-web