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

2015-01-28 Thread Mario Figueiredo
In article , 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 other purposes. > > In other words: That guide i

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

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

2015-01-27 Thread Ben Finney
Mario Figueiredo 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 > > > > Accord

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

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 resu

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) -- https://mail.python.org/mailman/listinfo/python

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): >

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 , > 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 corr

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

2015-01-27 Thread Mario Figueiredo
In article , 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. -- https://mail.python.org/mailman/listi

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 wrote: > On Jan 27, 2015 2:16 PM, "Neal Becker" wrote: > > > > Is there a more elegant way to spell this? > > > > for x in [_ for _ in seq if some_predicate]: > > for x in seq: >

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 possi

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): >

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_

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: >&

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

2015-01-27 Thread Jean-Michel Pichavant
- Original Message - > From: "Neal Becker" > 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

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" 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

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