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 current

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 instance, > so I can type > >

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

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

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 >

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

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

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

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 =

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.serial_number if l.wblist == >

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

Re: list comprehension return a list and sum over in loop

2014-12-13 Thread Mark Lawrence
On 13/12/2014 03:04, KK Sasa wrote: Sorry, i should say I'm using pythonxy, maybe it imports other things. That is good to know but without any context it's rather difficult to relate it to anything. Some people may have photographic memories and so remember everything that's been said in

Re: list comprehension return a list and sum over in loop

2014-12-13 Thread pecore
KK Sasa genwei...@gmail.com writes: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So results is a list consisting of 1000 lists, each of length four. Here, what I want to get is the

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread KK Sasa
Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道: On 12/12/2014 06:22, KK Sasa wrote: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So results is a list consisting of 1000

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Christian Gollwitzer
Am 12.12.14 09:30, schrieb KK Sasa: Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道: Hi Mark and Yotam, Thanks for kind reply. I think I didn't make my problem clear enough. The slow part is [d2(t[k]) for k in xrange(1000)]. In addition, I don't need to construct a list of 1000 lists inside, but

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Peter Otten
KK Sasa wrote: Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道: On 12/12/2014 06:22, KK Sasa wrote: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So results is a list

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread KK Sasa
Peter Otten於 2014年12月12日星期五UTC+8下午5時13分58秒寫道: KK Sasa wrote: Mark Lawrence於 2014年12月12日星期五UTC+8下午3時17分43秒寫道: On 12/12/2014 06:22, KK Sasa wrote: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Steven D'Aprano
KK Sasa wrote: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So results is a list consisting of 1000 lists, each of length four. Here, what I want to get is the sum of 1000 lists,

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Jussi Piitulainen
KK Sasa writes: def p(x,t,point,z,obs): d = x[0] tau = [0]+[x[1:point]] a = x[point:len(x)] at = sum(i*j for i, j in zip(a, t)) nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)] de = sum(nu, axis=0) probability = [nu[k]/de for k in xrange(point)]

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Peter Otten
Jussi Piitulainen wrote: KK Sasa writes: def p(x,t,point,z,obs): d = x[0] tau = [0]+[x[1:point]] a = x[point:len(x)] at = sum(i*j for i, j in zip(a, t)) nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)] de = sum(nu, axis=0) probability = [nu[k]/de

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread KK Sasa
Jussi Piitulainen於 2014年12月12日星期五UTC+8下午7時12分39秒寫道: KK Sasa writes: def p(x,t,point,z,obs): d = x[0] tau = [0]+[x[1:point]] a = x[point:len(x)] at = sum(i*j for i, j in zip(a, t)) nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)] de = sum(nu,

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread KK Sasa
Peter Otten於 2014年12月12日星期五UTC+8下午8時32分55秒寫道: Jussi Piitulainen wrote: KK Sasa writes: def p(x,t,point,z,obs): d = x[0] tau = [0]+[x[1:point]] a = x[point:len(x)] at = sum(i*j for i, j in zip(a, t)) nu = [exp(z[k]*(at-d)-sum(tau[k])) for k in xrange(point)]

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Peter Otten
KK Sasa wrote: Peter Otten於 2014年12月12日星期五UTC+8下午8時32分55秒寫道: Jussi Piitulainen wrote: KK Sasa writes: def p(x,t,point,z,obs): d = x[0] tau = [0]+[x[1:point]] a = x[point:len(x)] at = sum(i*j for i, j in zip(a, t)) nu = [exp(z[k]*(at-d)-sum(tau[k])) for k

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread Oscar Benjamin
On 12 December 2014 at 06:22, KK Sasa genwei...@gmail.com wrote: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So results is a list consisting of 1000 lists, each of length four.

Re: list comprehension return a list and sum over in loop

2014-12-12 Thread KK Sasa
Sorry, i should say I'm using pythonxy, maybe it imports other things. -- https://mail.python.org/mailman/listinfo/python-list

Re: list comprehension return a list and sum over in loop

2014-12-11 Thread Mark Lawrence
On 12/12/2014 06:22, KK Sasa wrote: Hi there, The list comprehension is results = [d2(t[k]) for k in xrange(1000)], where d2 is a function returning a list, say [x1,x2,x3,x4] for one example. So results is a list consisting of 1000 lists, each of length four. Here, what I want to get is the

Re: list comprehension misbehaving

2013-03-28 Thread Tim Chase
On 2013-03-28 15:25, Wolfgang Maier wrote: Dear all, with a=list(range(1,11)) why (in Python 2.7 and 3.3) is this explicit for loop working: for i in a[:-1]: a.pop() and a As you discover: Especially, since these two things *do* work as expected: [a.pop() and a[:] for i in a[:-1]]

Re: list comprehension misbehaving

2013-03-28 Thread Peter Otten
Wolfgang Maier wrote: Dear all, with a=list(range(1,11)) why (in Python 2.7 and 3.3) is this explicit for loop working: for i in a[:-1]: a.pop() and a giving: [1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 2, 3, 4, 5, 6, 7, 8] [1, 2, 3, 4, 5, 6, 7] [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5] [1, 2,

Re: list comprehension misbehaving

2013-03-28 Thread Wolfgang Maier
Tim Chase python.list at tim.thechases.com writes: it's because you're taking a snapshot copy of a in the middle of the loop. In your first example, if you change it to results = [] for i in a[:-1]: results.append(a.pop() and a) print results you get the same thing as your

Re: list comprehension misbehaving

2013-03-28 Thread duncan smith
On 28/03/13 15:25, Wolfgang Maier wrote: Dear all, with a=list(range(1,11)) why (in Python 2.7 and 3.3) is this explicit for loop working: for i in a[:-1]: a.pop() and a giving: [1, 2, 3, 4, 5, 6, 7, 8, 9] [1, 2, 3, 4, 5, 6, 7, 8] [1, 2, 3, 4, 5, 6, 7] [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5]

Re: List comprehension for testing **params

2012-11-12 Thread Ulrich Eckhardt
Am 11.11.2012 23:24, schrieb Cantabile: I'm writing a small mail library for my own use, and at the time I'm testing parameters like this: Let's ignore the facts that there is an existing mail library, that you should use real parameters if they are required and that exit() is completely

Re: List comprehension for testing **params

2012-11-12 Thread Joshua Landau
Just a few tricks you may have missed: On 12 November 2012 10:48, Ulrich Eckhardt ulrich.eckha...@dominolaser.comwrote: Am 11.11.2012 23:24, schrieb Cantabile: if required.intersection(params.**keys()) != required: if required.issubset(params): missing = required -

Re: List comprehension for testing **params

2012-11-12 Thread Joshua Landau
On 12 November 2012 13:23, Joshua Landau joshua.landau...@gmail.com wrote: Just a few tricks you may have missed: On 12 November 2012 10:48, Ulrich Eckhardt ulrich.eckha...@dominolaser.com wrote: Am 11.11.2012 23:24, schrieb Cantabile: if required.intersection(params.**keys()) !=

Re: List comprehension for testing **params

2012-11-12 Thread Cantabile
Wow, lots of things I had never heard of in your posts. I guess I need to do some homework... Cantabile -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension for testing **params

2012-11-11 Thread Ian Kelly
On Sun, Nov 11, 2012 at 3:24 PM, Cantabile cantabile...@wanadoo.fr wrote: I'd like to do something like that instead of the 'for' loop in __init__: assert[key for key in required if key in params.keys()] A list evaluates as true if it is not empty. As long as at least one of the required

Re: List comprehension for testing **params

2012-11-11 Thread Tim Chase
assert[key for key in required if key in params.keys()] ... Could you explain why it doesn't work and do you have any idea of how it could work ? Well, here, if any of the items are found, you get a list that is non-False'ish, so the assert passes. It sounds like you want all() (available as

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 23:24:14 +0100, Cantabile wrote: Hi, I'm writing a small mail library for my own use, and at the time I'm testing parameters like this: class Mail(object): def __init__(self, smtp, login, **params) blah blah required = ['Subject',

Re: List comprehension for testing **params

2012-11-11 Thread Terry Reedy
On 11/11/2012 5:56 PM, Ian Kelly wrote: On Sun, Nov 11, 2012 at 3:24 PM, Cantabile cantabile...@wanadoo.fr wrote: I'd like to do something like that instead of the 'for' loop in __init__: assert[key for key in required if key in params.keys()] A list evaluates as true if it is not empty. As

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 18:37:05 -0500, Terry Reedy wrote: or if you want them to be identified by keyword only (since 7 positional args is a bit much) def __init__(self, smtp, login, *, subject, from, to, msg): (I forget when this feature was added) It's a Python 3 feature. -- Steven --

Re: List comprehension for testing **params

2012-11-11 Thread Cantabile
Thanks everyone for your answers. That's much clearer now. I see that I was somehow fighting python instead of using it. Lesson learned (for the time being at least) :) I'll probably get back with more questions... Cheers, Cantabile -- http://mail.python.org/mailman/listinfo/python-list

Re: List comprehension for testing **params

2012-11-11 Thread Tim Chase
On 11/11/12 17:18, Steven D'Aprano wrote: but that leaves you with the next two problems: 2) Fixing the assert still leaves you with the wrong exception. You wouldn't raise a ZeroDivisionError, or a UnicodeDecodeError, or an IOError would you? No of course not. So why are you suggesting

Re: List comprehension for testing **params

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 18:21:32 -0600, Tim Chase wrote: On 11/11/12 17:18, Steven D'Aprano wrote: but that leaves you with the next two problems: 2) Fixing the assert still leaves you with the wrong exception. You wouldn't raise a ZeroDivisionError, or a UnicodeDecodeError, or an IOError

Re: list comprehension question

2012-10-17 Thread rusi
On Oct 17, 10:22 am, Terry Reedy tjre...@udel.edu wrote: On 10/16/2012 9:54 PM, Kevin Anthony wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. list comprehensions specifically abbreviate the code that they are (essentially)

Re: list comprehension question

2012-10-17 Thread Hans Mulder
On 17/10/12 09:13:57, rusi wrote: On Oct 17, 10:22 am, Terry Reedy tjre...@udel.edu wrote: On 10/16/2012 9:54 PM, Kevin Anthony wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. list comprehensions specifically abbreviate the code

Re: list comprehension question

2012-10-17 Thread Dave Angel
On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list comprehension is much faster the the for loops? If it is not the correct way of doing this, i appoligize. Like i said, I'm learing list comprehension. (Please don't top-post; it ruins the ordering. In these forums, put

Re: list comprehension question

2012-10-17 Thread rusi
On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote: On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list comprehension is much faster the the for loops? If it is not the correct way of doing this, i appoligize. Like i said, I'm learing list comprehension. list

Re: list comprehension question

2012-10-17 Thread rusi
On Oct 17, 7:06 pm, rusi rustompm...@gmail.com wrote: On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote: On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list comprehension is much faster the the for loops? If it is not the correct way of doing this, i appoligize.

Re: list comprehension question

2012-10-17 Thread Dave Angel
On 10/17/2012 10:06 AM, rusi wrote: On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote: On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list comprehension is much faster the the for loops? If it is not the correct way of doing this, i appoligize. Like i said, I'm learing

Re: list comprehension question

2012-10-17 Thread 88888 Dihedral
Dave Angel於 2012年10月17日星期三UTC+8下午10時37分01秒寫道: On 10/17/2012 10:06 AM, rusi wrote: On Oct 17, 5:33 pm, Dave Angel d...@davea.name wrote: On 10/17/2012 12:43 AM, Kevin Anthony wrote: Is it not true that list comprehension is much faster the the for loops? If it is not the correct

Re: list comprehension question

2012-10-17 Thread rusi
On Oct 17, 7:37 pm, Dave Angel d...@davea.name wrote: And I'd wager all the improvement is in the inner loop, the dot() function. Sorry -- red herring! Changing def mm1(a,b): return [[sum(x*y for x,y in zip(ra,rb)) for rb in zip(*b)] for ra in a] to def mm1(a,b): return [[sum([x*y for x,y

Re: list comprehension question

2012-10-17 Thread 88888 Dihedral
rusi於 2012年10月17日星期三UTC+8下午10時50分11秒寫道: On Oct 17, 7:37 pm, Dave Angel d...@davea.name wrote: And I'd wager all the improvement is in the inner loop, the dot() function. Sorry -- red herring! Changing def mm1(a,b): return [[sum(x*y for x,y in zip(ra,rb)) for rb in

Re: list comprehension question

2012-10-17 Thread Terry Reedy
On 10/17/2012 3:13 AM, rusi wrote: On Oct 17, 10:22 am, Terry Reedy tjre...@udel.edu wrote: On 10/16/2012 9:54 PM, Kevin Anthony wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. My response is to the part Kevin could *not* convert,

Re: list comprehension question

2012-10-17 Thread Oscar Benjamin
On 17 October 2012 06:09, Dwight Hutto dwightdhu...@gmail.com wrote: On Wed, Oct 17, 2012 at 12:43 AM, Kevin Anthony kevin.s.anth...@gmail.com wrote: Is it not true that list comprehension is much faster the the for loops? If it is not the correct way of doing this, i appoligize. Like i

Re: list comprehension question

2012-10-16 Thread Dave Angel
On 10/16/2012 09:54 PM, Kevin Anthony wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. here's the original code for matrix multiplcation retmatrix = Matrix(self.__row,other.__col) for m in range(0,retmatrix.__row): for n in

Re: list comprehension question

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 10:13 PM, Dwight Hutto dwightdhu...@gmail.com wrote: On Tue, Oct 16, 2012 at 9:54 PM, Kevin Anthony kevin.s.anth...@gmail.com wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. here's the original code for

Re: list comprehension question

2012-10-16 Thread Dwight Hutto
On Tue, Oct 16, 2012 at 10:13 PM, Dave Angel d...@davea.name wrote: On 10/16/2012 09:54 PM, Kevin Anthony wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. here's the original code for matrix multiplcation retmatrix =

Re: list comprehension question

2012-10-16 Thread rusi
On Oct 17, 7:14 am, Dave Angel d...@davea.name wrote: On 10/16/2012 09:54 PM, Kevin Anthony wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. here's the original code for matrix multiplcation retmatrix =

Re: list comprehension question

2012-10-16 Thread Kevin Anthony
Is it not true that list comprehension is much faster the the for loops? If it is not the correct way of doing this, i appoligize. Like i said, I'm learing list comprehension. Thanks Kevin On Oct 16, 2012 10:14 PM, Dave Angel d...@davea.name wrote: On 10/16/2012 09:54 PM, Kevin Anthony wrote:

Re: list comprehension question

2012-10-16 Thread Dwight Hutto
On Wed, Oct 17, 2012 at 12:43 AM, Kevin Anthony kevin.s.anth...@gmail.com wrote: Is it not true that list comprehension is much faster the the for loops? If it is not the correct way of doing this, i appoligize. Like i said, I'm learing list comprehension. I thought it was matrix

Re: list comprehension question

2012-10-16 Thread Terry Reedy
On 10/16/2012 9:54 PM, Kevin Anthony wrote: I've been teaching myself list comprehension, and i've run across something i'm not able to convert. list comprehensions specifically abbreviate the code that they are (essentially) equivalent to. res = [] for item in source: res.append(f(item))

Re: List comprehension/genexp inconsistency.

2012-03-21 Thread J. Cliff Dyer
Thanks, Ian. That does seem to explain it. The inner loop doesn't have access to the class's name space, and of course you can't fix it by referencing Foo.y explicitly, because the class isn't fully defined yet. Ultimately, we realized that the dict should be created in the __init__ method, so

Re: List comprehension/genexp inconsistency.

2012-03-20 Thread Ian Kelly
On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 20 Mar 2012 16:23:22 -0400, J. Cliff Dyer j...@sdf.lonestar.org declaimed the following in gmane.comp.python.general: When trying to create a class with a dual-loop generator expression in a class

Re: List comprehension/genexp inconsistency.

2012-03-20 Thread Steve Howell
On Mar 20, 3:50 pm, Ian Kelly ian.g.ke...@gmail.com wrote: On Tue, Mar 20, 2012 at 3:16 PM, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 20 Mar 2012 16:23:22 -0400, J. Cliff Dyer j...@sdf.lonestar.org declaimed the following in gmane.comp.python.general: When trying to create

Re: list comprehension question

2012-02-29 Thread James Broadhead
On 29 February 2012 13:52, Johann Spies johann.sp...@gmail.com wrote: In [82]: t.append(instansie) t.append(instansie) In [83]: t t Out[83]: ['Mangosuthu Technikon'] In [84]: t = [x.alt_name for x in lys].append(instansie) t = [x.alt_name for x in lys].append(instansie) In [85]: t t

Re: list comprehension question

2012-02-29 Thread John Gordon
In mailman.298.1330534919.3037.python-l...@python.org James Broadhead jamesbroadh...@gmail.com writes: On 29 February 2012 13:52, Johann Spies johann.sp...@gmail.com wrote: In [82]: t.append(instansie) t.append(instansie) In [83]: t t Out[83]: ['Mangosuthu Technikon'] In [84]: t

Re: list comprehension question

2012-02-29 Thread Chris Rebert
On Wed, Feb 29, 2012 at 5:52 AM, Johann Spies johann.sp...@gmail.com wrote: I understand the following: In [79]: instansie instansie Out[79]: 'Mangosuthu Technikon' In [80]: t = [x.alt_name for x in lys] t = [x.alt_name for x in lys] In [81]: t t Out[81]: [] In [82]:

Re: list comprehension question

2012-02-29 Thread Terry Reedy
On 2/29/2012 8:52 AM, Johann Spies wrote: Please post plain text, the standard for all python.org mailing lists and corresponding newsgroups, and not html. Some readers print the html as plain text, which is confusing and obnoxious. Other like mine, do skip the plain text version and print

Re: List comprehension timing difference.

2011-09-02 Thread Bart Kastermans
MRAB pyt...@mrabarnett.plus.com writes: On 02/09/2011 01:35, Bart Kastermans wrote: graph = [[a,b] for a in data for b in data if d(a,b) ==1 and a b] graph2 = [] for i in range (0, len(data)): for j in range(0,len(data)): if d(data[i],data[j]) == 1 and i j:

Re: List comprehension timing difference.

2011-09-02 Thread ting
On Sep 2, 9:54 am, Bart Kastermans bkast...@gmail.com wrote: if d(a,b) == 1 and a b: It will probably be faster if you reverse the evaluation order of that expression. if ab and d(a,b)==1: That way the d() function is called less than half the time. Of course this assumes that ab is a faster

Re: List comprehension timing difference.

2011-09-02 Thread Bart Kastermans
t...@thsu.org writes: On Sep 2, 9:54 am, Bart Kastermans bkast...@gmail.com wrote: if d(a,b) == 1 and a b: It will probably be faster if you reverse the evaluation order of that expression. if ab and d(a,b)==1: That way the d() function is called less than half the time. Of course this

Re: List comprehension timing difference.

2011-09-01 Thread MRAB
On 02/09/2011 01:35, Bart Kastermans wrote: In the following code I create the graph with vertices sgb-words.txt (the file of 5 letter words from the stanford graphbase), and an edge if two words differ by one letter. The two methods I wrote seem to me to likely perform the same computations,

Re: list comprehension to do os.path.split_all ?

2011-07-31 Thread Hrvoje Niksic
Neil Cerutti ne...@norwich.edu writes: On 2011-07-29, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: Fine... So normpath it first... os.path.normpath(r'C:/windows').split(os.sep) ['C:', 'windows'] That apparently doesn't distinguish between r'C:\windows' and r'C:windows'. On Windows

Re: list comprehension to do os.path.split_all ?

2011-07-30 Thread Michael Torrie
On Jul 29, 2011 6:33 PM, Michael Poeltl michael.poe...@univie.ac.at wrote: what about this? ' '.join('/home//h1122/bin///ghi/'.split('/')).split() ['home', 'h1122', 'bin', 'ghi'] Doesn't work on filenames with spaces in them. -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension to do os.path.split_all ?

2011-07-30 Thread Michael Poeltl
* Michael Torrie torr...@gmail.com [2011-07-31 03:44]: On Jul 29, 2011 6:33 PM, Michael Poeltl michael.poe...@univie.ac.at wrote: what about this? ' '.join('/home//h1122/bin///ghi/'.split('/')).split() ['home', 'h1122', 'bin', 'ghi'] Doesn't work on filenames with spaces in them.

Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread Neil Cerutti
On 2011-07-29, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Thu, 28 Jul 2011 15:31:43 -0600, Ian Kelly ian.g.ke...@gmail.com declaimed the following in gmane.comp.python.general: Using os.sep doesn't make it cross-platform. On Windows: os.path.split(r'C:\windows') ('C:\\',

Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread TheSaint
Alan Meyer wrote: This is not properly portable to all OS, but you could simply split on the slash character, e.g., pathname.split('/') more portable pathname.split(os.sep) -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread Carl Banks
On Thursday, July 28, 2011 2:31:43 PM UTC-7, Ian wrote: On Thu, Jul 28, 2011 at 3:15 PM, Emile van Sebille em...@fenx.com wrote: On 7/28/2011 1:18 PM gry said... [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.:    

Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread Alexander Kapps
On 29.07.2011 21:30, Carl Banks wrote: It's not even fullproof on Unix. '/home//h1122/bin///ghi/'.split('/') ['','home','','bin','','','ghi',''] The whole point of the os.path functions are to take care of whatever oddities there are in the path system. When you use string manipulation to

Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread Michael Poeltl
* Alexander Kapps alex.ka...@web.de [2011-07-29 22:30]: On 29.07.2011 21:30, Carl Banks wrote: It's not even fullproof on Unix. '/home//h1122/bin///ghi/'.split('/') ['','home','','bin','','','ghi',''] what about this? '

Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread Steven D'Aprano
Carl Banks wrote: It's not even fullproof on Unix. '/home//h1122/bin///ghi/'.split('/') ['','home','','bin','','','ghi',''] What? No. Absolutely not -- that would be a major bug. Did you actually try it? '/home//h1122/bin///ghi/'.split('/') ['', 'home', '', 'h1122', 'bin', '', '',

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Stefaan Himpe
Hi, [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.: '/home/gyoung/hacks/pathhack/foo.py' -- ['home', 'gyoung', 'hacks', 'pathhack', 'foo.py'] Not sure what your exact requirements are, but the following seems to work: pathname

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Neil Cerutti
On 2011-07-28, gry georgeryo...@gmail.com wrote: [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.: '/home/gyoung/hacks/pathhack/foo.py' -- ['home', 'gyoung', 'hacks', 'pathhack', 'foo.py'] os.path.split gives me a tuple of

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 2:18 PM, gry georgeryo...@gmail.com wrote: [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.:   '/home/gyoung/hacks/pathhack/foo.py'  --  ['home', 'gyoung', 'hacks', 'pathhack', 'foo.py'] os.path.split gives me a

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Alan Meyer
On 7/28/2011 4:18 PM, gry wrote: [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.: '/home/gyoung/hacks/pathhack/foo.py' -- ['home', 'gyoung', 'hacks', 'pathhack', 'foo.py'] os.path.split gives me a tuple of dirname,basename, but

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly ian.g.ke...@gmail.com wrote: path = '/home/gyoung/hacks/pathhack/foo.py' parts = [part for path, part in iter(lambda: os.path.split(path), ('/', ''))] parts.reverse() print parts But that's horrendously ugly.  Just write a generator with a while

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ethan Furman
Neil Cerutti wrote: If an elegant solution doesn't occur to me right away, then I first compose the most obvious solution I can think of. Finally, I refactor it until elegance is either achieved or imagined. +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 2:47 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Thu, Jul 28, 2011 at 2:44 PM, Ian Kelly ian.g.ke...@gmail.com wrote: path = '/home/gyoung/hacks/pathhack/foo.py' parts = [part for path, part in iter(lambda: os.path.split(path), ('/', ''))] parts.reverse() print parts

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Alexander Kapps
On 28.07.2011 22:44, Ian Kelly wrote: On Thu, Jul 28, 2011 at 2:18 PM, grygeorgeryo...@gmail.com wrote: [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.: '/home/gyoung/hacks/pathhack/foo.py' --['home', 'gyoung', 'hacks',

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Emile van Sebille
On 7/28/2011 1:18 PM gry said... [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.: '/home/gyoung/hacks/pathhack/foo.py' -- ['home', 'gyoung', 'hacks', 'pathhack', 'foo.py'] os.path.split gives me a tuple of dirname,basename, but

Re: list comprehension to do os.path.split_all ?

2011-07-28 Thread Ian Kelly
On Thu, Jul 28, 2011 at 3:15 PM, Emile van Sebille em...@fenx.com wrote: On 7/28/2011 1:18 PM gry said... [python 2.7] I have a (linux) pathname that I'd like to split completely into a list of components, e.g.:    '/home/gyoung/hacks/pathhack/foo.py'  --   ['home', 'gyoung', 'hacks',

Re: List comprehension vs filter()

2011-04-20 Thread Ian Kelly
On Tue, Apr 19, 2011 at 9:59 PM, Chris Angelico ros...@gmail.com wrote: On Wed, Apr 20, 2011 at 1:45 PM, Chris Rebert c...@rebertia.com wrote: Built-ins aren't quite the same as globals, but essentially yes: Sure. That might explain some of the weirdness, but it doesn't explain why things

Re: List comprehension vs filter()

2011-04-20 Thread Chris Angelico
On Wed, Apr 20, 2011 at 4:08 PM, Ian Kelly ian.g.ke...@gmail.com wrote: What is the scope the code is running in?  If this is part of a class definition, that could explain why the lambda is not seeing the type / posttype closure: because there isn't one. It's inside an if, but that's all. The

Re: List comprehension vs filter()

2011-04-20 Thread Tim Roberts
Chris Angelico ros...@gmail.com wrote: On Wed, Apr 20, 2011 at 1:45 PM, Chris Rebert c...@rebertia.com wrote: Built-ins aren't quite the same as globals, but essentially yes: Sure. That might explain some of the weirdness, but it doesn't explain why things were still weird with the variable

Re: List comprehension vs filter()

2011-04-20 Thread Chris Angelico
On Wed, Apr 20, 2011 at 5:16 PM, Tim Roberts t...@probo.com wrote: It's because, unlike some other languages (like Pascal), Python doesn't have infinitely recursive nested namespaces.  Glossing over details, there is a global namespace, and there is a local namespace.  A new function gets a

Re: List comprehension vs filter()

2011-04-20 Thread Steven D'Aprano
On Wed, 20 Apr 2011 13:10:21 +1000, Chris Angelico wrote: Context: Embedded Python interpreter, version 2.6.6 I have a list of dictionaries, where each dictionary has a type element which is a string. I want to reduce the list to just the dictionaries which have the same type as the first

  1   2   3   >