On Thu, Sep 1, 2022 at 9:16 AM Chris Angelico wrote:
> On Fri, 2 Sept 2022 at 02:10, James Tsai wrote:
> >
> > Hello,
> >
> > I find it very useful if I am allowed to define new local variables in a
> list comprehension. For example, I wish to have something like
ld example where you needed to
> write a series of statements or loops and (b) a corresponding example of
> how you would have preferred to have written that code, possibly
> inventing some syntax or misusing ":=" as if it workeed they way you'd
> like it to work?
&
ote:
> >
> > 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > > On 9/1/22, James Tsai wrote:
> > > >
> > > > I find it very useful if I am allowed to define new local variables
> in a
> > > > list comprehension. For example, I wish to have something l
On 02Sep2022 07:01, Chris Angelico wrote:
>On Fri, 2 Sept 2022 at 06:55, James Tsai wrote:
>> No but very often when I have written a neat list/dict/set
>> comprehension, I find it very necessary
>> to define local variable(s) to make it more clear and concise. Otherwise I
>> have to break it d
On 2022-09-01 13:33:16 -0700, James Tsai wrote:
> 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > On 9/1/22, James Tsai wrote:
> > >
> > > I find it very useful if I am allowed to define new local variables in a
> > > list comprehension. For example, I wish to have
On Fri, 2 Sept 2022 at 06:55, James Tsai wrote:
>
> 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > On 9/1/22, James Tsai wrote:
> > >
> > > I find it very useful if I am allowed to define new local variables in a
> > > list comprehension. For example, I wish to hav
在 2022年9月1日星期四 UTC+2 18:16:03, 写道:
> On Fri, 2 Sept 2022 at 02:10, James Tsai wrote:
> >
> > Hello,
> >
> > I find it very useful if I am allowed to define new local variables in a
> > list comprehension. For example, I wish to have something like
> >
在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> On 9/1/22, James Tsai wrote:
> >
> > I find it very useful if I am allowed to define new local variables in a
> > list comprehension. For example, I wish to have something like
> > [(x, y) for x in range(10) for y := x ** 2 if
在 2022年9月1日星期四 UTC+2 16:15:17, 写道:
> James Tsai writes:
>
> > I find it very useful if I am allowed to define new local variables in
> > a list comprehension. For example, I wish to have something like
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80
On 9/1/22, James Tsai wrote:
>
> I find it very useful if I am allowed to define new local variables in a
> list comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) with y := x
On Fri, 2 Sept 2022 at 02:10, James Tsai wrote:
>
> Hello,
>
> I find it very useful if I am allowed to define new local variables in a list
> comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [
James Tsai writes:
> I find it very useful if I am allowed to define new local variables in
> a list comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) with y := x ** 2 if x + y <
Hello,
I find it very useful if I am allowed to define new local variables in a list
comprehension. For example, I wish to have something like
[(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
[(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
For now this functionali
Op 16/08/2022 om 00:20 schreef dn:
On 16/08/2022 00.56, Antoon Pardon wrote:
Op 5/08/2022 om 07:50 schreef Loris Bennett:
Antoon Pardon writes:
Op 4/08/2022 om 13:51 schreef Loris Bennett:
Hi,
I am constructing a list of dictionaries via the following list
comprehension:
data
On 16/08/2022 00.56, Antoon Pardon wrote:
> Op 5/08/2022 om 07:50 schreef Loris Bennett:
>> Antoon Pardon writes:
>>
>>> Op 4/08/2022 om 13:51 schreef Loris Bennett:
>>>> Hi,
>>>>
>>>> I am constructing a list of dictionaries v
Op 5/08/2022 om 07:50 schreef Loris Bennett:
Antoon Pardon writes:
Op 4/08/2022 om 13:51 schreef Loris Bennett:
Hi,
I am constructing a list of dictionaries via the following list
comprehension:
data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
However
: Exclude 'None' from list comprehension of dicts
Antoon Pardon writes:
> Op 4/08/2022 om 13:51 schreef Loris Bennett:
>> Hi,
>>
>> I am constructing a list of dictionaries via the following list
>> comprehension:
>>
>>data = [get_job_efficiency_
Antoon Pardon writes:
> Op 4/08/2022 om 13:51 schreef Loris Bennett:
>> Hi,
>>
>> I am constructing a list of dictionaries via the following list
>> comprehension:
>>
>>data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
>>
>&g
. ***
On 2022-08-04 12:51, Loris Bennett wrote:
Hi,
I am constructing a list of dictionaries via the following list
comprehension:
data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
However,
get_job_efficiency_dict(job_id)
uses 'subprocess.Popen' to run an external program an
On 2022-08-04 12:51, Loris Bennett wrote:
Hi,
I am constructing a list of dictionaries via the following list
comprehension:
data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
However,
get_job_efficiency_dict(job_id)
uses 'subprocess.Popen' to run an external p
Op 4/08/2022 om 13:51 schreef Loris Bennett:
Hi,
I am constructing a list of dictionaries via the following list
comprehension:
data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
However,
get_job_efficiency_dict(job_id)
uses 'subprocess.Popen' to run an extern
Hi,
I am constructing a list of dictionaries via the following list
comprehension:
data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
However,
get_job_efficiency_dict(job_id)
uses 'subprocess.Popen' to run an external program and this can fail.
In this case, the d
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> "Loris Bennett" writes:
>>data = [get_job_efficiency_dict(job_id) for job_id in job_ids]
> ...
>>filtered_data = list(filter(None, data))
>
> You could have "get_job_efficiency_dict" return an iterable
> that yields either zero dictionaries or on
On 2020-09-25 7:46 AM, Chris Angelico wrote:
On Fri, Sep 25, 2020 at 3:43 PM Frank Millman wrote:
Hi all
I have a problem related (I think) to list comprehension namespaces. I
don't understand it enough to figure out a solution.
In the debugger, I want to examine the contents of the cu
On Fri, Sep 25, 2020 at 3:43 PM Frank Millman wrote:
>
> Hi all
>
> I have a problem related (I think) to list comprehension namespaces. I
> don't understand it enough to figure out a solution.
>
> In the debugger, I want to examine the contents of the current
Hi all
I have a problem related (I think) to list comprehension namespaces. I
don't understand it enough to figure out a solution.
In the debugger, I want to examine the contents of the current instance,
so I can type
(Pdb) dir(self)
and get the result with no problem.
However,
Nicholas Cole wrote:
[x.id for x in some_function()]
According to the profiler, some_function was being called 52,000 times
Is some_function recursive, by any chance?
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
The length of the list produced by the comprehension also give you good
information.
--
https://mail.python.org/mailman/listinfo/python-list
On Mon, Jul 22, 2019 at 11:33 PM Nicholas Cole wrote:
>
> I was profiling a slow function in an application last week, and came
> across something that I still can’t explain. Inside a loop that was being
> called 4 times, inside a for loop that ran for a few dozen times there was
> a list compress
The function IMHO must be returning a generator. I would look for a problem
in the generator code.
--
https://mail.python.org/mailman/listinfo/python-list
It is impossible to diagnose without seeing more context. Specifically,
you'll need to share the code around this line. The whole function,
preferably.
On Mon, Jul 22, 2019 at 9:31 AM Nicholas Cole
wrote:
> I was profiling a slow function in an application last week, and came
> across something
I was profiling a slow function in an application last week, and came
across something that I still can’t explain. Inside a loop that was being
called 4 times, inside a for loop that ran for a few dozen times there was
a list compression of the form:
[x.id for x in some_function()]
According to t
On 2018-01-15 00:01, Peng Yu wrote:
> Hi,
>
> I see the following usage of list comprehension can generate a
> generator. Does anybody know where this is documented? Thanks.
>
> $ cat main.py
> #!/usr/bin/env python
>
> import sys
> lines = (line.rstrip('
On 1/14/18 9:57 PM, Dan Stromberg wrote:
On Sun, Jan 14, 2018 at 3:01 PM, Peng Yu wrote:
Hi,
I see the following usage of list comprehension can generate a
generator. Does anybody know where this is documented? Thanks.
Here's the (a?) generator expression PEP:
https://www.python.org/dev
On Sun, Jan 14, 2018 at 3:01 PM, Peng Yu wrote:
> Hi,
>
> I see the following usage of list comprehension can generate a
> generator. Does anybody know where this is documented? Thanks.
Here's the (a?) generator expression PEP:
https://www.python.org/dev/peps/pep-0289/
Here
Peng Yu writes:
> > When you use square brackets, you're creating a generator, as in your
> > second example. Your first example is a slightly different beast
> > called a "generator expression". If you search for that in the docs or
> > on the web, you'll find what you want.
>
> Thanks. Can the
> When you use square brackets, you're creating a generator, as in your
> second example. Your first example is a slightly different beast
> called a "generator expression". If you search for that in the docs or
> on the web, you'll find what you want.
Thanks. Can the documentation be found by `he
On Mon, Jan 15, 2018 at 10:01 AM, Peng Yu wrote:
> Hi,
>
> I see the following usage of list comprehension can generate a
> generator. Does anybody know where this is documented? Thanks.
>
> $ cat main.py
> #!/usr/bin/env python
>
> import sys
> lines = (line.rstr
Hi,
I see the following usage of list comprehension can generate a
generator. Does anybody know where this is documented? Thanks.
$ cat main.py
#!/usr/bin/env python
import sys
lines = (line.rstrip('\n') for line in sys.stdin)
print lines
lines = [line.rstrip('\n') for line
On 12/30/2016 2:37 PM, Jason Friedman wrote:
Now, this puzzles me:
[x,y for a in data]
File "", line 1
[x,y for a in data]
^
SyntaxError: invalid syntax
I believe that python begins to parse this as
[x, (y for a in data)], a list of 2 items,
except that the required () are
> data = (
>> ... (1,2),
>> ... (3,4),
>> ... )
>>
> [x,y for a in data]
>> File "", line 1
>> [x,y for a in data]
>>^
>> SyntaxError: invalid syntax
>>
>> I expected:
>> [(1, 2), (3, 4)]
>
>
> Why would you expect that? I would expect the global variables x and y, or
> if
On Sat, 31 Dec 2016 06:37 am, Jason Friedman wrote:
> $ python
> Python 3.6.0 (default, Dec 26 2016, 18:23:08)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
data = (
> ... (1,2),
> ... (3,4),
> ... )
[a for a in data]
> [(1, 2), (3, 4)]
>
On Fri, Dec 30, 2016 at 2:58 PM, Joaquin Alzola
wrote:
>
>
>>Now, this puzzles me:
>
> [x,y for a in data]
>> File "", line 1
>>[x,y for a in data]
> > ^
>>SyntaxError: invalid syntax
>
>>I expected:
>>[(1, 2), (3, 4)]
>
> You can try [(x,z) for x,z in data].
> In your situation
>Now, this puzzles me:
[x,y for a in data]
> File "", line 1
>[x,y for a in data]
> ^
>SyntaxError: invalid syntax
>I expected:
>[(1, 2), (3, 4)]
You can try [(x,z) for x,z in data].
In your situation a takes the values (1,2) or (3,4) in the one that I put x and
z take the
On Fri, Dec 30, 2016 at 2:37 PM, Jason Friedman wrote:
> $ python
> Python 3.6.0 (default, Dec 26 2016, 18:23:08)
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
data = (
> ... (1,2),
> ... (3,4),
> ... )
[a for a in data]
> [(1, 2), (3, 4)
$ python
Python 3.6.0 (default, Dec 26 2016, 18:23:08)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> data = (
... (1,2),
... (3,4),
... )
>>> [a for a in data]
[(1, 2), (3, 4)]
Now, this puzzles me:
>>> [x,y for a in data]
File "", line 1
[x
On Saturday, 1 October 2016 14:17:06 UTC+10, Rustom Mody wrote:
> On Saturday, October 1, 2016 at 9:08:09 AM UTC+5:30, Sayth Renshaw wrote:
> > I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if
> > there are better non list comprehension opt
On Saturday, 1 October 2016 14:17:06 UTC+10, Rustom Mody wrote:
> On Saturday, October 1, 2016 at 9:08:09 AM UTC+5:30, Sayth Renshaw wrote:
> > I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if
> > there are better non list comprehension opt
On Saturday, October 1, 2016 at 9:08:09 AM UTC+5:30, Sayth Renshaw wrote:
> I do like [(f + ['0'] if len(f) < 5 else f) for f in fups ] Rustom, if there
> are better non list comprehension options I would like to know as generally I
> find then confusing.
Two po
r fups.append(0)]
> > print(fups)
>
> > Unsure why I cannot use append in this instance
>
> Because that's incorrect syntax.
>
> > how can I modify to acheive desired output?
>
> for f in fups:
> if len(f) < 5:
> f.append(0
eive desired output?
>
> for f in fups:
> if len(f) < 5:
> f.append(0)
>
> Or, if you really want to use a list comprehension:
>
> [f.append(0) for f in fups if len(f) < 5]
Wrong
fups = [['0', '0', '0',
27;firstup'])
> [x[4] for x in fups if IndexError fups.append(0)]
> print(fups)
> Unsure why I cannot use append in this instance
Because that's incorrect syntax.
> how can I modify to acheive desired output?
for f in fups:
if len(f) < 5:
f.append
I have a list of lists of numbers like this excerpt.
['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['0', '0', '0', '0']
['7', '2', '1', '0', '142647', '00']
['7', '2', '0', '1', '87080', '00']
['6', '1', '1', '1', '51700', '00']
['4', '1',
On 5/10/2016 3:34 PM, Terry Reedy wrote:
On 5/10/2016 9:51 AM, Claudiu Popa wrote:
Thank you for letting us know. While pylint is indeed
opinionated in some cases, we're not trying to be
"arrogant", as you put it, towards Guido or the other core
developers. What's sad in this particular case is
On Wed, May 11, 2016 at 1:35 AM, wrote:
> Basically, pylint overwhelms the user
> right now with its enabled checks and we're trying to split these
> into tiers, as seen in the following:
>
> $ pylint myproject
> # core checkers enabled
> 10/10 - Congrats, you're clean on a core. You
On 5/10/2016 11:35 AM, pcmantic...@gmail.com wrote:
The bad-builtin check is now an extension, so using the first case
would enable it.
The 'old' (not 'bad') builtin check should include using map instead of
a comprehension. The check should also pay attention to whether the
function argume
On 5/10/2016 9:51 AM, Claudiu Popa wrote:
Thank you for letting us know. While pylint is indeed
opinionated in some cases, we're not trying to be
"arrogant", as you put it, towards Guido or the other core
developers. What's sad in this particular case is that the
feedback had to come in rather a
On Tuesday, May 10, 2016 at 5:58:37 PM UTC+3, Steven D'Aprano wrote:
> Hi Claudiu,
>
>
> On Tue, 10 May 2016 11:51 pm, Claudiu Popa wrote:
>
> > Thank you for letting us know. While pylint is indeed
> > opinionated in some cases, we're not trying to be
> > "arrogant", as you put it, towards Guid
A further comment:
On Tue, 10 May 2016 11:51 pm, Claudiu Popa wrote:
> Thank you for letting us know. While pylint is indeed
> opinionated in some cases, we're not trying to be
> "arrogant",
And from the docs:
"What Pylint says is not to be taken as gospel and Pylint isn’t smarter than
you are
Hi Claudiu,
On Tue, 10 May 2016 11:51 pm, Claudiu Popa wrote:
> Thank you for letting us know. While pylint is indeed
> opinionated in some cases, we're not trying to be
> "arrogant", as you put it, towards Guido or the other core
> developers. What's sad in this particular case is that the
> fe
On Sunday, May 8, 2016 at 4:41:02 AM UTC+3, Terry Reedy wrote:
> On 5/7/2016 3:17 PM, Christopher Reimer wrote:
>
> > For my purposes, I'm using the list comprehension over filter to keep
> > pylint happy.
>
> How sad. The pylint developers arrogantly take it on t
On 5/8/2016 5:02 AM, Steven D'Aprano wrote:
On Sun, 8 May 2016 08:01 am, Christopher Reimer wrote:
On 5/7/2016 2:22 PM, Chris Angelico wrote:
Also, be sure you read this part of PEP 8:
https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds
Recrui
On Sun, 8 May 2016 08:01 am, Christopher Reimer wrote:
> On 5/7/2016 2:22 PM, Chris Angelico wrote:
>> Also, be sure you read this part of PEP 8:
>>
>>
https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds
> Recruiters and hiring managers *are* hobgoblin
On 5/7/2016 6:40 PM, Terry Reedy wrote:
On 5/7/2016 3:17 PM, Christopher Reimer wrote:
For my purposes, I'm using the list comprehension over filter to keep
pylint happy.
How sad. The pylint developers arrogantly take it on themselves to
revise Python, against the wishes of Guido an
On Sun, 8 May 2016 07:35 am, Stephen Hansen wrote:
> I'd read over PEP8 (the document, not the tool) and
> apply style guide recommendations thoughtfully, not mechanically.
Guido is not a fan of automated PEP8 checkers. He agrees entirely with your
comment: apply style guides thoughtfully, not m
On 5/7/2016 3:17 PM, Christopher Reimer wrote:
For my purposes, I'm using the list comprehension over filter to keep
pylint happy.
How sad. The pylint developers arrogantly take it on themselves to
revise Python, against the wishes of Guido and the other core
developers, and you and
On 5/7/2016 1:31 PM, Marko Rauhamaa wrote:
Christopher Reimer :
Never know when an asshat hiring manager would reject my resume out of
hand because my code fell short with pylint.
Remember that it's not only the company checking you out but also you
checking the company out.
Would you want to
as
> Pythonic and PEP8-compliant as possible. That includes scoring 10/10 with
> pylint. Never know when an asshat hiring manager would reject my resume out
> of hand because my code fell short with pylint.
>
> For my purposes, I'm using the list comprehension over filter to ke
possible. That includes scoring
10/10 with pylint. Never know when an asshat hiring manager would
reject my resume out of hand because my code fell short with pylint.
For my purposes, I'm using the list comprehension over filter to keep
pylint happy.
Wrong thinking. Make it Pythonic - but do
ython! Check out my chess engine code on GitHub!"), I want it to be as
>> Pythonic and PEP8-compliant as possible. That includes scoring 10/10
>> with pylint. Never know when an asshat hiring manager would reject my
>> resume out of hand because my code fell short with pylint.
and PEP8-compliant as possible. That includes scoring 10/10
> with pylint. Never know when an asshat hiring manager would reject my
> resume out of hand because my code fell short with pylint.
>
> For my purposes, I'm using the list comprehension over filter to keep
> pylint h
On 05/07/2016 05:22 PM, Chris Angelico wrote:
On Sun, May 8, 2016 at 5:17 AM, Christopher Reimer
wrote:
pylint. Never know when an asshat hiring manager would reject my resume out
of hand because my code fell short with pylint.
I see that as a good motivation to make sure your code was go
it to be as
> Pythonic and PEP8-compliant as possible. That includes scoring 10/10 with
> pylint. Never know when an asshat hiring manager would reject my resume out
> of hand because my code fell short with pylint.
>
> For my purposes, I'm using the list comprehension over filte
Christopher Reimer :
> Never know when an asshat hiring manager would reject my resume out of
> hand because my code fell short with pylint.
Remember that it's not only the company checking you out but also you
checking the company out.
Would you want to work for an asshat hiring manager?
Of cou
ct my
resume out of hand because my code fell short with pylint.
For my purposes, I'm using the list comprehension over filter to keep
pylint happy.
Thank you,
Chris R.
--
https://mail.python.org/mailman/listinfo/python-list
On 5/5/2016 7:57 PM, Stephen Hansen wrote:
On Thu, May 5, 2016, at 07:46 PM, Dan Sommers wrote:
On Thu, 05 May 2016 18:37:11 -0700, Stephen Hansen wrote:
''.join(x for x in string if x.isupper())
The difference is, both filter and your list comprehension *build a
list* wh
On Fri, 6 May 2016 12:57 pm, Stephen Hansen wrote:
> On Thu, May 5, 2016, at 07:46 PM, Dan Sommers wrote:
>> On Thu, 05 May 2016 18:37:11 -0700, Stephen Hansen wrote:
>>
>> > ''.join(x for x in string if x.isupper())
>>
>> > The difference i
On Fri, May 6, 2016 at 1:07 PM, Dan Sommers wrote:
> On Fri, 06 May 2016 02:46:22 +, Dan Sommers wrote:
>
>> Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
>> [GCC 5.3.1 20160409] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> filter
On Fri, 06 May 2016 02:46:22 +, Dan Sommers wrote:
> Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
> [GCC 5.3.1 20160409] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> filter(lambda x:x+1, [1, 2, 3, 4])
> [1, 2, 3, 4]
>
> P
On Thu, May 5, 2016, at 07:46 PM, Dan Sommers wrote:
> On Thu, 05 May 2016 18:37:11 -0700, Stephen Hansen wrote:
>
> > ''.join(x for x in string if x.isupper())
>
> > The difference is, both filter and your list comprehension *build a
> > list* which i
On Fri, May 6, 2016 at 12:46 PM, Dan Sommers wrote:
> filter used to build a list, but now it doesn't (where "used to" means
> Python 2.7 and "now" means Python 3.5; I'm too lazy to track down the
> exact point(s) at which it changed):
>
> Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
>
On Thu, 05 May 2016 18:37:11 -0700, Stephen Hansen wrote:
> ''.join(x for x in string if x.isupper())
> The difference is, both filter and your list comprehension *build a
> list* which is not needed, and wasteful. The above skips building a
> list, instead returning a
is, I believe, that list comprehensions
are good, and using them is great.
In your case, though, I would not use a list comprehension. I'd use a
generator comprehension. It looks almost identical:
''.join(x for x in string if x.isupper())
The difference is, both filter and your
and dandy. Except Pylint doesn't like it. According to this
> link, list comprehensions have replaced filters and the Pylint warning can
> be disabled.
>
> http://stackoverflow.com/questions/3569134/why-doesnt-pylint-like-built-in-functions
>
> Here's the replacem
ehensions have replaced filters and the Pylint
warning can be disabled.
http://stackoverflow.com/questions/3569134/why-doesnt-pylint-like-built-in-functions
Here's the replacement code using list comprehension:
''.join([x for x in string if x.isupper()])
Which is one is correct
Op 26-11-15 om 16:36 schreef Marko Rauhamaa:
> Antoon Pardon :
>
>> [ for in ]
>>
>> would implicitly be rewritten as follows:
>>
>> [ (lambda : )() for in ]
>
> Funny enough, that's how "list comprehensions" are created in Scheme:
>
>(map (lambda (i)
> (lambda (x) (* i
Antoon Pardon writes:
> Op 26-11-15 om 14:56 schreef Marko Rauhamaa:
>> Antoon Pardon wrote:
>>
>>> I don't understand. What I propose would be a minor change in how
>>> list comprehension works. I don't see how your example can be turned
>>> int
Antoon Pardon :
> [ for in ]
>
> would implicitly be rewritten as follows:
>
> [ (lambda : )() for in ]
Funny enough, that's how "list comprehensions" are created in Scheme:
(map (lambda (i)
(lambda (x) (* i x)))
'(0 1 2 3
> There would no change on how lamb
Op 26-11-15 om 14:56 schreef Marko Rauhamaa:
> Antoon Pardon :
>
>> I don't understand. What I propose would be a minor change in
>> how list comprehension works. I don't see how your example
>> can be turned into a list comprehension.
> The list compre
Antoon Pardon :
> I don't understand. What I propose would be a minor change in
> how list comprehension works. I don't see how your example
> can be turned into a list comprehension.
The list comprehension is only a special case of the interaction between
closures and varia
> return i * x
> q.append(stepper)
>
> print(n)
> print(q[1]())
> print(n)
> x = "there"
> print(q[3]())
> print(n)
>
> which prints:
>
> 0
> hellohellohello
> 1
> theretherethere
>
[3]())
print(n)
which prints:
0
hellohellohello
1
theretherethere
2
after your change, you'd get:
0
hello
0
hellohellohello
0
> It also seems that people who try this for the first time are
> surprised with what they get and seem to expect there list
&
and [(lambda x: )(x) for x in
]
The only exceptions seems to be when is itself a lambda.
It also seems that people who try this for the first time are surprised
with what they get and seem to expect there list comprehension to
act as if they had written the second version.
So would it be adv
On Wed, 25 Nov 2015 14:51:23 +0100, Antoon Pardon wrote:
> Am I missing something?
The issue is with lambdas rather than with list comprehensions per se.
Python's lambdas capture free variables by reference, not value.
> x = 3
> f = lambda y: x + y
> f(0)
3
ge(4)]" gives
>> a list of essentially the same functions?
>
> Can you (or someone else) explain what a list comprehension is equivallent of.
> Especially in python3.
I am not sure about "Python3" (never used it), but in Python 2,
the simple list comprehension "
tially the same functions?
Can you (or someone else) explain what a list comprehension is equivallent of.
Especially in python3.
Take this simple list comprhesion:
[x * x for x in range(10)]
what would this be equivallent of? Something like:
def lch1():
ls = []
for x in range(10):
ls.appe
On Wed, Oct 28, 2015 at 12:36 PM, Zachary Ware
wrote:
> On Wed, Oct 28, 2015 at 11:25 AM, Larry Martell
> wrote:
>> I'm trying to do a list comprehension with an if and that requires an
>> else, but in the else case I do not want anything added to the list.
>>
Hi Larry,
On 10/28/2015 10:25 AM, Larry Martell wrote:
> I'm trying to do a list comprehension with an if and that requires an
> else, but in the else case I do not want anything added to the list.
>
> For example, if I do this:
>
> white_list = [l.control_hub.se
On Wed, Oct 28, 2015 at 11:25 AM, Larry Martell wrote:
> I'm trying to do a list comprehension with an if and that requires an
> else, but in the else case I do not want anything added to the list.
>
> For example, if I do this:
>
> white_list = [l.control_hub.se
I'm trying to do a list comprehension with an if and that requires an
else, but in the else case I do not want anything added to the list.
For example, if I do this:
white_list = [l.control_hub.serial_number if l.wblist ==
wblist_enum['WHITE'] else None for l in wblist]
I end
1 - 100 of 1035 matches
Mail list logo