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
- 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
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
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
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
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)
--
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.
--
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
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
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
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
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
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
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?
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
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
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
17 matches
Mail list logo