Re: Is there a more elegant way to spell this?

2015-01-28 Thread Mario Figueiredo
In article mailman.18197.1422408555.18130.python-l...@python.org, ben+pyt...@benfinney.id.au says... More accurately (and as acknowledged in that guide), a single underscore *is* a common name for a ?don't care? name, but is better avoided for that purpose because it's also commonly used for

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jean-Michel Pichavant
- Original Message - From: Neal Becker ndbeck...@gmail.com To: python-list@python.org Sent: Tuesday, 27 January, 2015 2:15:12 PM Subject: Is there a more elegant way to spell this? Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: You could

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Rustom Mody
On Tuesday, January 27, 2015 at 6:45:41 PM UTC+5:30, Neal Becker wrote: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: Depends on what follows the ':' In the trivial case all thats outside the comprehension can be dropped: [x for x in [y for y

Re: Is there a more elegant way to spell this?

2015-01-27 Thread random832
On Tue, Jan 27, 2015, at 13:05, Mario Figueiredo wrote: In article qot7fw8s3la@ruuvi.it.helsinki.fi, jpiit...@ling.helsinki.fi says... If you mean literally some_predicate, then perhaps this. if some_predicate: for x in seq: handle(x) Careful. See Chris Warrick

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Neal Becker
Jussi Piitulainen wrote: Neal Becker writes: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: If you mean some_predicate(_), then possibly this. for x in filter(some_predicate, seq): handle(x) If you mean literally some_predicate

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Emile van Sebille
On 1/27/2015 9:49 AM, Rob Gaddi wrote: Or the somewhat less indenty for x in seq: if not some_predicate: continue do_something_to(x) ... or shorter and equally less indenty for x in seq: if some_predicate: do_something_to(x) --

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Mario Figueiredo
In article qot7fw8s3la@ruuvi.it.helsinki.fi, jpiit...@ling.helsinki.fi says... If you mean literally some_predicate, then perhaps this. if some_predicate: for x in seq: handle(x) Careful. See Chris Warrick answer for the correct position of the 'if' statement. --

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Steven D'Aprano
Neal Becker wrote: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: Don't use _ as the loop variable here. There are three common conventions for _ and this is none of them: (1) n the interactive interpreter _ is used for the result of the last

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Mario Figueiredo
In article 54c8339f$0$13008$c3e8da3$54964...@news.astraweb.com, steve+comp.lang.pyt...@pearwood.info says... (3) _ is also commonly used as a don't care variable name: a, _, b, _ = get_four_items() # but I only care about two of them According to the following link, it is actually a

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Ben Finney
Mario Figueiredo mar...@gmail.com writes: In article 54c8339f$0$13008$c3e8da3$54964...@news.astraweb.com, steve+comp.lang.pyt...@pearwood.info says... (3) _ is also commonly used as a don't care variable name: a, _, b, _ = get_four_items() # but I only care about two of them

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Neal Becker
Jussi Piitulainen wrote: Neal Becker writes: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: If you mean some_predicate(_), then possibly this. for x in filter(some_predicate, seq): handle(x) I like this best, except probably even better

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jussi Piitulainen
Neal Becker writes: Jussi Piitulainen wrote: Neal Becker writes: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: If you mean some_predicate(_), then possibly this. for x in filter(some_predicate, seq): handle(x) I like

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Jussi Piitulainen
Neal Becker writes: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: If you mean some_predicate(_), then possibly this. for x in filter(some_predicate, seq): handle(x) If you mean literally some_predicate, then perhaps this. if some_predicate

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Steven D'Aprano
Mario Figueiredo wrote: In article 54c8339f$0$13008$c3e8da3$54964...@news.astraweb.com, steve+comp.lang.pyt...@pearwood.info says... (3) _ is also commonly used as a don't care variable name: a, _, b, _ = get_four_items() # but I only care about two of them According to the following

Is there a more elegant way to spell this?

2015-01-27 Thread Neal Becker
Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: -- -- Those who don't understand recursion are doomed to repeat it -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Chris Warrick
On Jan 27, 2015 2:16 PM, Neal Becker ndbeck...@gmail.com wrote: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: for x in seq: if some_predicate: do_something_to(x) -- Chris Warrick https://chriswarrick.com/ Sent from my Galaxy S3

Re: Is there a more elegant way to spell this?

2015-01-27 Thread Rob Gaddi
On Tue, 27 Jan 2015 14:20:10 +0100 Chris Warrick kwpol...@gmail.com wrote: On Jan 27, 2015 2:16 PM, Neal Becker ndbeck...@gmail.com wrote: Is there a more elegant way to spell this? for x in [_ for _ in seq if some_predicate]: for x in seq: if some_predicate