Re: Local variable definition in Python list comprehension

2022-09-02 Thread Dan Stromberg
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

Re: Local variable definition in Python list comprehension

2022-09-02 Thread James Tsai
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? &

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Avi Gross
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

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Cameron Simpson
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

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Peter J. Holzer
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

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Chris Angelico
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

Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 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 > >

Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 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

Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 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

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Eryk Sun
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

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Chris Angelico
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 > [

Re: Local variable definition in Python list comprehension

2022-09-01 Thread Ben Bacarisse
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 <

Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
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

Re: Exclude 'None' from list comprehension of dicts

2022-08-16 Thread Antoon Pardon
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

Re: Exclude 'None' from list comprehension of dicts

2022-08-15 Thread 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 v

Re: Exclude 'None' from list comprehension of dicts

2022-08-15 Thread Antoon Pardon
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

RE: Exclude 'None' from list comprehension of dicts

2022-08-05 Thread avi.e.gross
: 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_

Re: Exclude 'None' from list comprehension of dicts

2022-08-05 Thread 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] >> >&g

Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread Weatherby,Gerard
. *** 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

Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread MRAB
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

Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread Antoon Pardon
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

Exclude 'None' from list comprehension of dicts

2022-08-04 Thread 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 external program and this can fail. In this case, the d

Re: Exclude 'None' from list comprehension of dicts

2022-08-04 Thread Loris Bennett
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

Re: list comprehension namespace problem

2020-09-24 Thread Frank Millman
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

Re: list comprehension namespace problem

2020-09-24 Thread Chris Angelico
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

list comprehension namespace problem

2020-09-24 Thread Frank Millman
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,

Re: List comprehension strangeness

2019-07-22 Thread Gregory Ewing
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

Re: List comprehension strangeness

2019-07-22 Thread Bob Gailer
The length of the list produced by the comprehension also give you good information. -- https://mail.python.org/mailman/listinfo/python-list

Re: List comprehension strangeness

2019-07-22 Thread Chris Angelico
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

Re: List comprehension strangeness

2019-07-22 Thread Bob Gailer
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

Re: List comprehension strangeness

2019-07-22 Thread Calvin Spealman
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

List comprehension strangeness

2019-07-22 Thread Nicholas Cole
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

Re: Where is the usage of (list comprehension) documented?

2018-01-15 Thread Thomas Jollans
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('

Re: Where is the usage of (list comprehension) documented?

2018-01-15 Thread Ned Batchelder
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

Re: Where is the usage of (list comprehension) documented?

2018-01-14 Thread Dan Stromberg
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&#

Re: Where is the usage of (list comprehension) documented?

2018-01-14 Thread Ben Finney
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

Re: Where is the usage of (list comprehension) documented?

2018-01-14 Thread Peng Yu
> 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

Re: Where is the usage of (list comprehension) documented?

2018-01-14 Thread Chris Angelico
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

Where is the usage of (list comprehension) documented?

2018-01-14 Thread Peng Yu
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

Re: List comprehension

2016-12-30 Thread Terry Reedy
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

Re: List comprehension

2016-12-30 Thread Jason Friedman
> 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

Re: List comprehension

2016-12-30 Thread Steve D'Aprano
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)] >

Re: List comprehension

2016-12-30 Thread Joel Goldstick
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

RE: List comprehension

2016-12-30 Thread Joaquin Alzola
>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

Re: List comprehension

2016-12-30 Thread Joel Goldstick
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)

List comprehension

2016-12-30 Thread Jason Friedman
$ 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

Re: how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw
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

Re: how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw
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

Re: how to append to list in list comprehension

2016-09-30 Thread Rustom Mody
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

Re: how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw
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

Re: how to append to list in list comprehension

2016-09-30 Thread Rustom Mody
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', &#x

Re: how to append to list in list comprehension

2016-09-30 Thread John Gordon
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

how to append to list in list comprehension

2016-09-30 Thread Sayth Renshaw
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',

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread DFS
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

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread Chris Angelico
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

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread Terry Reedy
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

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread Terry Reedy
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

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread pcmanticore
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

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread Steven D'Aprano
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

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread Steven D'Aprano
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

Re: Pylint prefers list comprehension over filter...

2016-05-10 Thread Claudiu Popa
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

Re: Pylint prefers list comprehension over filter...

2016-05-08 Thread Christopher Reimer
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

Re: Pylint prefers list comprehension over filter...

2016-05-08 Thread Steven D'Aprano
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Christopher Reimer
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Steven D'Aprano
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Terry Reedy
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Christopher Reimer
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Radek Holý
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Christopher Reimer
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Chris Angelico
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.

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Stephen Hansen
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Nathan Hilterbrand
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Chris Angelico
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Marko Rauhamaa
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Christopher Reimer
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

Re: Pylint prefers list comprehension over filter...

2016-05-07 Thread Christopher Reimer
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

Re: Pylint prefers list comprehension over filter...

2016-05-06 Thread Steven D'Aprano
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

Re: Pylint prefers list comprehension over filter...

2016-05-05 Thread Chris Angelico
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

Re: Pylint prefers list comprehension over filter...

2016-05-05 Thread Dan Sommers
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

Re: Pylint prefers list comprehension over filter...

2016-05-05 Thread Stephen Hansen
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

Re: Pylint prefers list comprehension over filter...

2016-05-05 Thread Chris Angelico
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) >

Re: Pylint prefers list comprehension over filter...

2016-05-05 Thread Dan Sommers
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

Re: Pylint prefers list comprehension over filter...

2016-05-05 Thread Stephen Hansen
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

Re: Pylint prefers list comprehension over filter...

2016-05-05 Thread Chris Angelico
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

Pylint prefers list comprehension over filter...

2016-05-05 Thread Christopher Reimer
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

Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
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

Re: What does a list comprehension do

2015-11-26 Thread Jussi Piitulainen
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

Re: What does a list comprehension do

2015-11-26 Thread 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 x))) '(0 1 2 3 > There would no change on how lamb

Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
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

Re: What does a list comprehension do

2015-11-26 Thread 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 comprehension is only a special case of the interaction between closures and varia

Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
> 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 >

Re: What does a list comprehension do

2015-11-26 Thread Marko Rauhamaa
[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 &

Re: What does a list comprehension do

2015-11-26 Thread Antoon Pardon
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

Re: What does a list comprehension do (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?))

2015-11-26 Thread Nobody
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

Re: What does a list comprehension do

2015-11-25 Thread dieter
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 "

What does a list comprehension do (was: Late-binding of function defaults (was Re: What is a function parameter =[] for?))

2015-11-25 Thread Antoon Pardon
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

Re: List comprehension with if-else

2015-10-28 Thread Larry Martell
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. >>

Re: List comprehension with if-else

2015-10-28 Thread Carl Meyer
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

Re: List comprehension with if-else

2015-10-28 Thread Zachary Ware
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

List comprehension with if-else

2015-10-28 Thread Larry Martell
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   2   3   4   5   6   7   8   9   10   >