Re: Map vs. List Comprehensions (was "lint warnings")

2011-02-16 Thread Steven D'Aprano
On Tue, 15 Feb 2011 18:55:50 -0500, Gerald Britton wrote: > So, what's the feeling out there? Go with map and the operators or > stick with the list comps? Stick to whatever feels and reads better at the time. Unless you have profiled your code, and determined that the map or list comp was the

Re: Map Linux locale codes to Windows locale codes?

2010-12-14 Thread Flávio Lisbôa
You could look into the windows registry, the key "HKLM\SYSTEM\CurrentControlSet\Control\Nls" has all the supported LCID's listed. If not, you could simply get the codepage provided by locale.setlocale(), e.g.: import locale print(locale.setlocale(locale.LC_ALL, "")) prints "Portuguese_Brazil.125

Re: map is useless!

2010-06-07 Thread James Mills
On Mon, Jun 7, 2010 at 9:20 AM, Steven D'Aprano wrote: >> Ruby has a very nice map > > I'm thrilled for them. Personally I think the syntax is horrible. I concur! --James -- http://mail.python.org/mailman/listinfo/python-list

Re: map is useless!

2010-06-06 Thread Terry Reedy
On 6/6/2010 7:20 PM, Steven D'Aprano wrote: On Sun, 06 Jun 2010 08:16:02 -0700, rantingrick wrote: Everyone knows i'm a Python fanboy so nobody can call me a troll for this... The first rule of trolling is, always deny being a troll, no matter how obvious the trolling. Such as the exagerate

Re: map is useless!

2010-06-06 Thread Carl Banks
On Jun 6, 8:16 am, rantingrick wrote: > Everyone knows i'm a Python fanboy so nobody can call me a troll for > this... 1. I don't remember you so I don't know if you're a Python fanboy or not 2. If you act like a troll I'll call you one even if you are Python fanboy Actually, your post only came

Re: map is useless!

2010-06-06 Thread D'Arcy J.M. Cain
On Mon, 07 Jun 2010 10:16:19 +1000 Lie Ryan wrote: > On 06/07/10 09:56, D'Arcy J.M. Cain wrote: > > Show me the unit test that defines the problem. > > that you must use foo() and you can't change foo() (since foo is very > complex), and you give the same result as the original solution. I rejec

Re: map is useless!

2010-06-06 Thread Lie Ryan
On 06/07/10 09:56, D'Arcy J.M. Cain wrote: > On Mon, 07 Jun 2010 05:59:02 +1000 > Lie Ryan wrote: >>> foo = lambda x: [y + 1 for y in x] >>> [foo(x) for x in [[4, 6, 3], [6, 3, 2], [1, 3, 5]]] >>> >>> Didn't seem like such a long walk. >>> >> >> that's because you're simplifying the problem, the c

Re: map is useless!

2010-06-06 Thread D'Arcy J.M. Cain
On Mon, 07 Jun 2010 05:59:02 +1000 Lie Ryan wrote: > > foo = lambda x: [y + 1 for y in x] > > [foo(x) for x in [[4, 6, 3], [6, 3, 2], [1, 3, 5]]] > > > > Didn't seem like such a long walk. > > > > that's because you're simplifying the problem, the correct walk is: Well, since it gives the same

Re: map is useless!

2010-06-06 Thread Steven D'Aprano
On Sun, 06 Jun 2010 08:16:02 -0700, rantingrick wrote: > Everyone knows i'm a Python fanboy so nobody can call me a troll for > this... The first rule of trolling is, always deny being a troll, no matter how obvious the trolling. But on the chance I'm wrong, and for the benefit of others, your

Re: map is useless!

2010-06-06 Thread Terry Reedy
On 6/6/2010 11:16 AM, rantingrick wrote: Everyone knows i'm a Python fanboy so nobody can call me a troll for this... Non sequitor. It depends on your intention in posting this... Python map is just completely useless. For one it so damn slow Posting invalid speed comparisons stacked agains

Re: map is useless!

2010-06-06 Thread rantingrick
On Jun 6, 2:48 pm, Richard Thomas wrote: > Python's map has the useful feature that nobody is in any doubt about > what it does. I don't know much about Ruby I have to say but looking > at that piece of syntax you gave I had no idea how to interpret it. > Anyway, I looked it up. Well Ruby likes t

Re: map is useless!

2010-06-06 Thread Lie Ryan
On 06/07/10 05:54, D'Arcy J.M. Cain wrote: > On Mon, 07 Jun 2010 05:27:43 +1000 > Lie Ryan wrote: >> In the most naive uses, map appears to have no advantage over list >> comprehension; but one thing that map can do that list comprehension >> still can't do without a walk around the park: >> >> de

Re: map is useless!

2010-06-06 Thread D'Arcy J.M. Cain
On Mon, 07 Jun 2010 05:27:43 +1000 Lie Ryan wrote: > In the most naive uses, map appears to have no advantage over list > comprehension; but one thing that map can do that list comprehension > still can't do without a walk around the park: > > def foo(func, args): > g = lambda x: x+1 > re

Re: map is useless!

2010-06-06 Thread Richard Thomas
Python's map has the useful feature that nobody is in any doubt about what it does. I don't know much about Ruby I have to say but looking at that piece of syntax you gave I had no idea how to interpret it. Anyway, I looked it up. Calling an method on each of a collection of objects is best accomp

Re: map is useless!

2010-06-06 Thread Thomas Jollans
On 06/06/2010 05:16 PM, rantingrick wrote: > So can anyone explain this poor excuse for a map function? Maybe GVR > should have taken it out in 3.0? *scratches head* > > Speaking of Py3k: map no longer builds lists. What once was map is no more, what once was itertools.imap is now map. Sometim

Re: map is useless!

2010-06-06 Thread Lie Ryan
On 06/07/10 03:22, rantingrick wrote: > On Jun 6, 12:02 pm, Alain Ketterlin > wrote: >> rantingrick writes: >> I've not used map since I learned about list comprehensions. > > Thats has been my experienced also. Actually i've been at Python for > O... about 2 years now and i don't think i've eve

Re: map is useless!

2010-06-06 Thread rantingrick
On Jun 6, 12:02 pm, Alain Ketterlin wrote: > rantingrick writes: > I've not used map since I learned about list comprehensions. Thats has been my experienced also. Actually i've been at Python for O... about 2 years now and i don't think i've ever used map in a script even one time until a month

Re: map is useless!

2010-06-06 Thread Shashwat Anand
map is not needed. LC is great :D On Sun, Jun 6, 2010 at 10:32 PM, Alain Ketterlin < al...@dpt-info.u-strasbg.fr> wrote: > rantingrick writes: > > > Python map is just completely useless. [...] > > import time > def test1(): > > l = range(1) > > t1 = time.time() > >

Re: map is useless!

2010-06-06 Thread Alain Ketterlin
rantingrick writes: > Python map is just completely useless. [...] import time def test1(): > l = range(1) > t1 = time.time() > map(lambda x:x+1, l) > t2= time.time() > print t2-t1 def test2(): > l = range(1) > t1 = time.time() >

Re: map is useless!

2010-06-06 Thread Duncan Booth
rantingrick wrote: > Python map is just completely useless. For one it so damn slow why > even bother putting it in the language? And secondly, the total "girl- > man" weakness of lambda renders it completely mute! Do you realise that you don't have to use lambda? If you need more than a single

Re: map is useless!

2010-06-06 Thread Roald de Vries
On Jun 6, 2010, at 5:16 PM, rantingrick wrote: Everyone knows i'm a Python fanboy so nobody can call me a troll for this... Python map is just completely useless. For one it so damn slow why even bother putting it in the language? And secondly, the total "girl- man" weakness of lambda renders it

Re: map is useless!

2010-06-06 Thread James Mills
On Mon, Jun 7, 2010 at 1:16 AM, rantingrick wrote: > So can anyone explain this poor excuse for a map function? Maybe GVR > should have taken it out in 3.0?  *scratches head* Let me get this straight... You're complaining about some trivial code you've written and a 0.002 or less execution time ?

Re: map, index

2010-03-28 Thread Luis Quesada
Paul Rubin wrote: Luis Quesada writes: [ id*v for id,v in enumerate(L) ] Cool! Thanks! If you really want to write that in pointfree style (untested): import itertools, operator ... itertools.starmap(operator.mul, enumerate(L)) For your other question, you could probably do someth

Re: map, index

2010-03-28 Thread Paul Rubin
Luis Quesada writes: >> [ id*v for id,v in enumerate(L) ] > Cool! Thanks! If you really want to write that in pointfree style (untested): import itertools, operator ... itertools.starmap(operator.mul, enumerate(L)) For your other question, you could probably do something ugly with ifil

Re: map, index

2010-03-28 Thread Luis Quesada
Duncan Booth wrote: Luis Quesada wrote: Is there a way of writing the following without using zip: map(lambda (id,v):id*v,zip(range(len(L)),L)) [ id*v for id,v in enumerate(L) ] Cool! Thanks! Cheers, Luis -- http://mail.python.org/mailman/listinfo/python-list

Re: map, index

2010-03-28 Thread Duncan Booth
Luis Quesada wrote: > Is there a way > of writing the following without using zip: > map(lambda (id,v):id*v,zip(range(len(L)),L)) [ id*v for id,v in enumerate(L) ] -- http://mail.python.org/mailman/listinfo/python-list

Re: map

2009-09-02 Thread Hendrik van Rooyen
On Wednesday 02 September 2009 09:38:20 elsa wrote: > > in my own defense - firstly, I was able to implement what I wanted to > do with loops, and I used this to solve the problem I needed to. My rant was not intended as a personal attack - far from it - if all the people on this list were to po

Re: map

2009-09-02 Thread elsa
On Aug 31, 11:44 pm, Hendrik van Rooyen wrote: > On Monday 31 August 2009 11:31:34 Piet van Oostrum wrote: > > > But ultimately it is also very much a matter of taste, preference and > > habit. > > This is true, but there is another reason that I posted - I have noticed that > there seems to be a

Re: map

2009-09-01 Thread Jan Kaliszewski
Another possibilities, if you really *desire* to use map() and not list-comprehension (I'd prefer the latter), are: # Python 2.x: map(func, mylist, itertools.repeat('booHoo', len(mylist))) # Python 3.x, where map() works like Py2.x's itertools.imap(): list(map(func, mylist, itertools.repeat('boo

Re: map

2009-08-31 Thread alex23
Piet van Oostrum wrote: > [myFunc(elt, 'booHoo') for elt in myList] is also a good candidate and > in this case I think it is preferable to both the loop and the map with > a partial or lambda in terms of clarity. >From memory, a listcomp with a non-builtin function is also faster than map with t

Re: map

2009-08-31 Thread Nobody
On Sun, 30 Aug 2009 21:55:52 -0700, elsa wrote: > say I have a list, myList. Now say I have a function with more than > one argument: > > myFunc(a, b='None') > > now, say I want to map myFunc onto myList, with always the same > argument for b, but iterating over a: > > map(myFunc(b='booHoo'), m

Re: map

2009-08-31 Thread Paul Rubin
elsa writes: > map(myFunc(b='booHoo'), myList) > > Why doesn't this work? is there a way to make it work? You can use functools.partial but a listcomp might be simpler: list(myfunc(a, b='booHoo') for a in myList) There is another listcomp syntax with square brackets, but I try to avoid it b

Re: map

2009-08-31 Thread Hendrik van Rooyen
On Monday 31 August 2009 11:31:34 Piet van Oostrum wrote: > But ultimately it is also very much a matter of taste, preference and > habit. This is true, but there is another reason that I posted - I have noticed that there seems to be a tendency amongst newcomers to the group to go to great len

Re: map

2009-08-31 Thread Steven D'Aprano
On Mon, 31 Aug 2009 10:43:07 +0200, Hendrik van Rooyen wrote: > Here is some heretical advice: > > Do not use stuff like map and reduce unless they fit what you want to do > perfectly, and "JustWorks" the first time. > > You have a very clear idea of what you want to do, so why do you not > just

Re: map

2009-08-31 Thread Piet van Oostrum
> Hendrik van Rooyen (HvR) wrote: >HvR> On Monday 31 August 2009 06:55:52 elsa wrote: >HvR> 8< - map question >>> >>> (Ultimately, I want to call myFunc(myList[0], 'booHoo'), myFunc(myList >>> [1], 'booHoo'), myFunc(myList[2], 'booHoo') etc. However, I m

Re: map

2009-08-31 Thread Gabriel Genellina
En Mon, 31 Aug 2009 05:43:07 -0300, Hendrik van Rooyen escribió: On Monday 31 August 2009 06:55:52 elsa wrote: (Ultimately, I want to call myFunc(myList[0], 'booHoo'), myFunc(myList [1], 'booHoo'), myFunc(myList[2], 'booHoo') etc. However, I might want to call myFunc(myList[0], 'woo'), myFunc

Re: map

2009-08-31 Thread Hendrik van Rooyen
On Monday 31 August 2009 06:55:52 elsa wrote: 8< - map question > > (Ultimately, I want to call myFunc(myList[0], 'booHoo'), myFunc(myList > [1], 'booHoo'), myFunc(myList[2], 'booHoo') etc. However, I might want > to call myFunc(myList[0], 'woo'), myFunc(myLis

Re: map

2009-08-30 Thread Wolfgang Strobl
elsa : >now, say I want to map myFunc onto myList, with always the same >argument for b, but iterating over a: >>> from functools import partial >>> def g(x,y=1): return x+y ... >>> map(partial(g,y=2),[1,2]) [3, 4] >>> map(partial(g,y=42),[1,2]) [43, 44] -- Wir danken für die Beachtung aller S

Re: map

2009-08-30 Thread rurpy
On 08/30/2009 10:55 PM, elsa wrote: > i have a question about the built in map function. Here 'tis: > > say I have a list, myList. Now say I have a function with more than > one argument: > > myFunc(a, b='None') > > now, say I want to map myFunc onto myList, with always the same > argument for b, b

Re: map

2009-08-30 Thread Chris Rebert
On Sun, Aug 30, 2009 at 9:55 PM, elsa wrote: > Hi, > > i have a question about the built in map function. Here 'tis: > > say I have a list, myList. Now say I have a function with more than > one argument: > > myFunc(a, b='None') > > now, say I want to map myFunc onto myList, with always the same >

Re: Map with an extra parameter

2006-09-09 Thread Peter Otten
ml1n wrote: > I'm not really sure how to explain this so maybe some example code is > best. This code makes a list of objects by taking a list of ints and > combining them with a constant: > > class foo: > def __init__(self): > self.a = 0 > self.b = 0 > > def func(a,b): > f = new

Re: Map with an extra parameter

2006-09-09 Thread Simon Forman
ml1n wrote: > [EMAIL PROTECTED] wrote: > > This may be what you need: > > > > class foo: > > def __init__(self, a, b): > > self.a = a > > self.b = b > > > > vars = [1,2,3,4,5,6] > > objects = [foo(a, 1) for a in vars] > > > > > > Note that in Python the new is expressed wit the () at th

Re: Map with an extra parameter

2006-09-08 Thread bearophileHUGS
ml1n: > Looks like someone already did: > http://mail.python.org/pipermail/python-list/2005-January/259870.html Don't belive too much in such general timings. Time your specific code when you think you need a true answer. Timing Python code is very easy and fast, and sometimes results are surprisi

Re: Map with an extra parameter

2006-09-08 Thread ml1n
[EMAIL PROTECTED] wrote: > ml1n wrote: > > In the interests of speed my thinking was that using map would move the > > loop out of Python and into C, is that the case when using list > > comprehension? I'd always thought it was just syntatic short hand for > > a Python loop. > > In Python the fast

Re: Map with an extra parameter

2006-09-08 Thread Paul Rubin
"ml1n" <[EMAIL PROTECTED]> writes: > In the interests of speed my thinking was that using map would move the > loop out of Python and into C, is that the case when using list > comprehension? I'd always thought it was just syntatic short hand for > a Python loop. Best to run benchmarks, but I don

Re: Map with an extra parameter

2006-09-08 Thread bearophileHUGS
ml1n wrote: > In the interests of speed my thinking was that using map would move the > loop out of Python and into C, is that the case when using list > comprehension? I'd always thought it was just syntatic short hand for > a Python loop. In Python the faster things are often the most simple. Y

Re: Map with an extra parameter

2006-09-08 Thread ml1n
[EMAIL PROTECTED] wrote: > This may be what you need: > > class foo: > def __init__(self, a, b): > self.a = a > self.b = b > > vars = [1,2,3,4,5,6] > objects = [foo(a, 1) for a in vars] > > > Note that in Python the new is expressed wit the () at the end: > > > f = new foo() > > Bye,

Re: Map with an extra parameter

2006-09-08 Thread bearophileHUGS
This may be what you need: class foo: def __init__(self, a, b): self.a = a self.b = b vars = [1,2,3,4,5,6] objects = [foo(a, 1) for a in vars] Note that in Python the new is expressed wit the () at the end: > f = new foo() Bye, bearophile -- http://mail.python.org/mailman/list

Re: map() return of flat tuple list

2006-06-23 Thread bearophileHUGS
Mirco: >He, this looks more like Haskell than like Python (for me, it looks awful ;-) Maybe this is more readable: ar = [[3,3,3,3], [3,3,3,1], [3,3,4,3]] print sorted( [(r,c) for r,row in enumerate(ar) for c in xrange(len(row))], key=lambda (r,c): ar[r][c] )

Re: map() return of flat tuple list

2006-06-23 Thread Mirco Wahab
Thus spoke [EMAIL PROTECTED] (on 2006-06-23 00:57): > Maybe you want something like this (but this doesn't use map): > [(r,c) for r, row in enumerate(m) for c in xrange(len(row))] Ahh, its a 'list comprehension', nice. Now, lets see how the decorate/undecorate sort turns out to look in Python:

Re: map() return of flat tuple list

2006-06-22 Thread bearophileHUGS
Maybe you want something like this (but this doesn't use map): def indexes(m): return [(r,c) for r, row in enumerate(m) for c in xrange(len(row))] m1 = [[2,2,5], [2,2], [2,2,2,2]] m2 = [[], [2], [1,2,3,4]] print indexes(m1) print indexes(m2) Output: [(0, 0), (0, 1),

Re: Map port to process

2006-01-05 Thread Mike Meyer
"py" <[EMAIL PROTECTED]> writes: > Is there a way in python to figure out which process is running on > which port? I know in Windows XP you can run "netstat -o" and see the > process ID for each open portbut I am looking for something not > tied to windows particularly, hopefully something in

Re: Map port to process

2006-01-05 Thread Diez B. Roggisch
py wrote: > Is there a way in python to figure out which process is running on > which port? I know in Windows XP you can run "netstat -o" and see the > process ID for each open portbut I am looking for something not > tied to windows particularly, hopefully something in python. > > if not,

Re: Map of email origins to Python list

2005-11-08 Thread Alan Kennedy
[Claire McLister] > I've made the script available on our downloads page at: > > http://www.zeesource.net/downloads/e2i [Alan Kennedy] >> I look forward to the map with updated precision :-) [Claire McLister] > Me too. Please let me know how we should modify the script. Having examined your sc

Re: Map of email origins to Python list

2005-11-07 Thread Claire McLister
On Nov 7, 2005, at 3:26 PM, Alan Kennedy wrote: > Sure, please do make it available, or at least the geolocation > component > anyway. I'm sure you'll get lots of useful comments from the many > clever > and experienced folk who frequent this group. > I've made the script available on our downl

Re: Map of email origins to Python list

2005-11-07 Thread Mike Meyer
Claire McLister <[EMAIL PROTECTED]> writes: > Thanks, Alan. You are absolutely right, we are not using the > NNTP-Posting-Host header for obtaining the IP address. Yes, but what are you using? > The Python list is unique among the lists that we have handled so far, > in that it has a cross-postin

Re: Map of email origins to Python list

2005-11-07 Thread Alan Kennedy
[Claire McLister] > Thanks, Alan. You are absolutely right, we are not using the > NNTP-Posting-Host header for obtaining the IP address. Aha, that would explain the lack of precision in many cases. A lot of posters in this list/group go through NNTP (either with an NNTP client or through NNTP-

Re: Map of email origins to Python list

2005-11-07 Thread Claire McLister
Thanks, Alan. You are absolutely right, we are not using the NNTP-Posting-Host header for obtaining the IP address. The Python list is unique among the lists that we have handled so far, in that it has a cross-posting mechanism with a net news. Hence, it seems we are getting many more wrong loc

Re: Map of email origins to Python list

2005-11-07 Thread Jorge Godoy
"George Sakkis" <[EMAIL PROTECTED]> writes: > "Jorge Godoy" <[EMAIL PROTECTED]>: > > > H... I don't see mine listed there: I'm in South America, Brasil. More > > specifically in Curitiba, Paraná, Brasil. :-) > > That's funny; I was looking for mine and I stumbled across yours at > Piscataw

Re: Map of email origins to Python list

2005-11-07 Thread Alan Kennedy
[Alan Kennedy] >>So presumably "chcgil" indicates you're in Chicago, Illinois? [EMAIL PROTECTED] > Yes, but why, then, is my name logged into Mountain View, CA? Presumably the creators of the map have chosen to use a mechanism other than NNTP-Posting-Host IP address to geolocate posters. Claire

Re: Map of email origins to Python list

2005-11-07 Thread George Sakkis
"Jorge Godoy" <[EMAIL PROTECTED]>: > H... I don't see mine listed there: I'm in South America, Brasil. More > specifically in Curitiba, Paraná, Brasil. :-) That's funny; I was looking for mine and I stumbled across yours at Piscataway, NJ, US. :-) George -- http://mail.python.org/mailman

Re: Map of email origins to Python list

2005-11-07 Thread [EMAIL PROTECTED]
Alan Kennedy wrote: > [Robert Kern] > >>Most of AOL's offices are in Dulles, VA. Google's headquarters are in > >>Mountain View, CA. > > [EMAIL PROTECTED] > > Aha, I post to the usenet through Google. Makes the map application > > all the more stupid, doesn't it? > > Actually, no, because Google G

Re: Map of email origins to Python list

2005-11-07 Thread Alan Kennedy
[Robert Kern] >>Most of AOL's offices are in Dulles, VA. Google's headquarters are in >>Mountain View, CA. [EMAIL PROTECTED] > Aha, I post to the usenet through Google. Makes the map application > all the more stupid, doesn't it? Actually, no, because Google Groups sets the NNTP-Posting-Host head

Re: Map of email origins to Python list

2005-11-07 Thread [EMAIL PROTECTED]
Robert Kern wrote: > [EMAIL PROTECTED] wrote: > > > North of that bubble is a second massive list also labeled Mountain > > View > > 94043. I found my name on that list and I live in the Chicago area. > > Moutain View is, perhaps, where aol.com is located? These bubbles are > > showing the locatio

Re: Map of email origins to Python list

2005-11-07 Thread Robert Kern
[EMAIL PROTECTED] wrote: > North of that bubble is a second massive list also labeled Mountain > View > 94043. I found my name on that list and I live in the Chicago area. > Moutain View is, perhaps, where aol.com is located? These bubbles are > showing the location of the server that's registered

Re: Map of email origins to Python list

2005-11-07 Thread Rocco Moretti
[EMAIL PROTECTED] wrote: > Rocco Moretti wrote: > >>It's also a testament to the limited value of physically locating people >>by internet addresses - If you zoom in on the San Fransico bay area, and >>click on the southern most bubble (south of San Jose), you'll see the >>entry for the Mountain Vi

Re: Map of email origins to Python list

2005-11-07 Thread [EMAIL PROTECTED]
Rocco Moretti wrote: > Paul McGuire wrote: > > "Claire McLister" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > We've been working with Google Maps, and have created a web service to > > map origins of emails to a group. As a trial, we've developed a map of > > emails to thi

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-08 Thread Terry Reedy
"George Sakkis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Steven Bethard" <[EMAIL PROTECTED]> wrote: >> Dict comprehensions were recently rejected: >> http://www.python.org/peps/pep-0274.html >> The reason, of course, is that dict comprehensions don't gain you much >> a

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-08 Thread George Sakkis
"Steven Bethard" <[EMAIL PROTECTED]> wrote: > Christopher Subich wrote: > > Ron Adam wrote: > >> I think the association of (lambda) to [list_comp] is a nice > >> distinction. Maybe a {dictionary_comp} would make it a complete set. ;-) > > > > Yeah, dictionary comprehensions would be an interesti

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-08 Thread Steven Bethard
Christopher Subich wrote: > Ron Adam wrote: >> I think the association of (lambda) to [list_comp] is a nice >> distinction. Maybe a {dictionary_comp} would make it a complete set. ;-) > > Yeah, dictionary comprehensions would be an interesting feature. :) > Syntax might be a bit unwieldy, thoug

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Christopher Subich
Ron Adam wrote: > Christopher Subich wrote: > >> As others have mentioned, this looks too much like a list >> comprehension to be elegant, which also rules out () and {}... but I >> really do like the infix syntax. > > > Why would it rule out ()? Generator expressions. Mind you, Py3k might w

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Erik Max Francis wrote: > Ron Adam wrote: > >> Well in my previous explanation I *mean* it to be empty parenthesis. >> >> Does that help? > > > Maybe it might be beneficial to learn a little more of the language > before proposing such wide-reaching (and un-Pythonic) reforms? Hi Erik, Getting

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Erik Max Francis
Ron Adam wrote: > Well in my previous explanation I *mean* it to be empty parenthesis. > > Does that help? Maybe it might be beneficial to learn a little more of the language before proposing such wide-reaching (and un-Pythonic) reforms? -- Erik Max Francis && [EMAIL PROTECTED] && http://www.

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Erik Max Francis wrote: > Ron Adam wrote: > >> It's not an empty tuple, it's an empty parenthesis. Using tuples it >> would be. >> >> (a,) == (,) >> >> which would be the same as: >> >> (,) == (,) > > > >>> () > () > >>> a = () > >>> type(a) > > >>> (,) > File "", line 1 > (,) >

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Christopher Subich wrote: > As others have mentioned, this looks too much like a list comprehension > to be elegant, which also rules out () and {}... but I really do like > the infix syntax. Why would it rule out ()? You need to put a lambda express in ()'s anyways if you want to use it righ

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Erik Max Francis
Ron Adam wrote: > It's not an empty tuple, it's an empty parenthesis. Using tuples it > would be. > > (a,) == (,) > > which would be the same as: > > (,) == (,) >>> () () >>> a = () >>> type(a) >>> (,) File "", line 1 (,) ^ SyntaxError: invalid syntax You've wandered way

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Christopher Subich
Terry Hancock wrote: > With list comprehensions and generators becoming so integral, I'm > not sure about "unpythonic". And a syntax just occured to me -- > what about this: > > [y*x for x,y] > > ? > > (that is: > > [ for ] > > It's just like the beginning of a list comprehension or generator

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Ron Adam wrote: > Reinhold Birkenfeld wrote: >> Ron Adam wrote: >>>(a) == () >> >> >> Whoops! a (which is None) is equal to the empty tuple (which is not None)? > > It's not an empty tuple, it's an empty parenthesis. Using tuples it > would be. But empty parenthesis a

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Terry Hancock
On Wednesday 06 July 2005 08:38 am, Tom Anderson wrote: > On Wed, 6 Jul 2005, Terry Hancock wrote: > > With list comprehensions and generators becoming so integral, I'm > > not sure about "unpythonic". > > I'm going to resist the temptation to argue that list comps are themselves > unpythonic :).

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-07 Thread Terry Reedy
"Stian Søiland" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On 2005-07-06 02:46:27, George Sakkis wrote: >> So, who would object the full-word versions for python 3K ? >> def -> define >> del -> delete >> exec -> execute >> elif -> else if >Objections for the "else if" might be

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Terry Hancock
On Wednesday 06 July 2005 09:41 am, Steven Bethard wrote: > Terry Hancock wrote: > > And a syntax just occured to me -- what about this: > > [ for ] > > If you haven't already, see: > http://wiki.python.org/moin/AlternateLambdaSyntax > for other similar proposals. Yeah, it's basically "Robert Bre

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-07 Thread Terry Reedy
"Pawe³ Sakowski" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Tom Anderson wrote: > def flatten(ll): > return reduce(lambda a, l: a.extend(l), ll, []) > > How would one do that as a list comp, by the way? I'm really not very > good > with them yet. Not really a list-comprehensio

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions andbackground unscientific mini-survey]

2005-07-07 Thread Terry Reedy
The difference in readability between func = lambda x: x**3 - 5*x def func(x): return x**3 - 5*x def func(x): return x**3 - 5*x is obviously a matter of personal vision. The fuctional difference (and, I believe, the only difference) is that the def form attaches the specific name 'func' t

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Daniel Schüle
> Am I just weird? I feel the same way about where to use lambda's and where *not* I come from C and C++ background and defining a function at the top level (no nested functions) would always require good reasons function name has to be remembered, to put it in other words it has to be added in

Re: Deleting variables [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Tom Anderson
On Thu, 7 Jul 2005, Steven D'Aprano wrote: > On Wed, 06 Jul 2005 14:28:55 +0100, Tom Anderson wrote: > >>> del -> delete >> >> How about just getting rid of del? Removal from collections could be done >> with a method call, > > Which would be called object.del() I presume. That would be fine. >

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Ron Adam
Steven D'Aprano wrote: > On Thu, 07 Jul 2005 09:36:24 +, Duncan Booth wrote: > > >>Steven D'Aprano wrote: >> >>>This is something I've never understood. Why is it bad >>>form to assign an "anonymous function" (an object) to a >>>name? >> >>Because it obfuscates your code for no benefit. Yo

Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-07 Thread Tom Anderson
On Thu, 7 Jul 2005, Ron Adam wrote: Stian Søiland wrote: > Or what about a recursive generator? That's the sort of thing i like to see! Ok, lets see... I found a few problems with the testing (and corrected it) so the scores have changed. My sort in place routines were cheating because t

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Bengt Richter
On 7 Jul 2005 15:46:23 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: >Steven D'Aprano wrote: > >> Put it this way: whenever I see a two-line def as above, I can't help >> feeling that it is a waste of a def. ("Somebody went to all the trouble >> to define a function for *that*?") Yet I would never

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Reinhold Birkenfeld wrote: > Ron Adam wrote: > > >>Given the statement: >> >>a = None >> >>And the following are all true: >> >> a == None > > > Okay. > > >>(a) == (None) > > > Okay. > > >>(a) == () > > > Whoops! a (which is None) is equal to the empty tuple (which is not None)? It's

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Sion Arrowsmith
=?ISO-8859-2?Q?Pawe=B3?= Sakowski <[EMAIL PROTECTED]> wrote: ll=[[1,2],[3,4,5],[6]] sum(ll,[]) >[1, 2, 3, 4, 5, 6] That's a great argument for list.__add__ having the semantics of extend rather than append 8-) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Fra

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Duncan Booth
Steven D'Aprano wrote: > Put it this way: whenever I see a two-line def as above, I can't help > feeling that it is a waste of a def. ("Somebody went to all the trouble > to define a function for *that*?") Yet I would never think the same about > a lambda -- lambdas just feel like they should be l

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Steven D'Aprano
On Thu, 07 Jul 2005 09:36:24 +, Duncan Booth wrote: > Steven D'Aprano wrote: >> This is something I've never understood. Why is it bad >> form to assign an "anonymous function" (an object) to a >> name? > > Because it obfuscates your code for no benefit. You should avoid making it > hard f

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Paweł Sakowski
Tom Anderson wrote: > def flatten(ll): > return reduce(lambda a, l: a.extend(l), ll, []) > > How would one do that as a list comp, by the way? I'm really not very good > with them yet. Not really a list-comprehension based solution, but I think what you want is >>> ll=[[1,2],[3,4,5],[6]] >>> su

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-07 Thread Chris Rebert (cybercobra)
Agreed, I dislike map and its ilk as well. However, they are handy in some cases. I particularly like the way Ruby deals with this problem. Instead of all these functions, internal iterators and true anonymous blocks are used. Case in point: def gt_than_5(obj): return obj > 5 results = filter(

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Duncan Booth
Steven D'Aprano wrote: > This is something I've never understood. Why is it bad > form to assign an "anonymous function" (an object) to a > name? Because it obfuscates your code for no benefit. You should avoid making it hard for others to read your code (and 'others' includes yourself in the

Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Steven D'Aprano
Steven Bethard wrote: > If you're really afraid of two lines, write it as: > > def r(): randint(1, 100) > > This is definitely a bad case for an anonymous function because it's not > anonymous! You give it a name, r. This is something I've never understood. Why is it bad form to assign a

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Reinhold Birkenfeld
Ron Adam wrote: > Given the statement: > > a = None > > And the following are all true: > > a == None Okay. > (a) == (None) Okay. > (a) == () Whoops! a (which is None) is equal to the empty tuple (which is not None)? > (None) == () > > Then this "conceptual" comparison should also be tr

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Mike Meyer wrote: > Ron Adam <[EMAIL PROTECTED]> writes: > >>So doing this would give an error for functions that require an argument. >> >> def foo(x): >> return x >> >> a = None >> b = foo(a)# error because a dissapears before foo gets it. > > > So how do I pass None

Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-06 Thread Ron Adam
Stian Søiland wrote: > Or what about a recursive generator? > > a = [1,2,[[3,4],5,6],7,8,[9],[],] > > def flatten(item): > try: > iterable = iter(item) > except TypeError: > yield item # inner/final clause > else: > for elem in

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Mike Meyer
Ron Adam <[EMAIL PROTECTED]> writes: > So doing this would give an error for functions that require an argument. > > def foo(x): > return x > > a = None > b = foo(a)# error because a dissapears before foo gets it. So how do I pass None to a function? > >>TypeErro

  1   2   3   >