From: rantingrick on 6 Jun 2010 13:22 On Jun 6, 12:02 pm, Alain Ketterlin <al...(a)dpt-info.u-strasbg.fr> wrote: > rantingrick <rantingr...(a)gmail.com> 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 or so ago. After a few unit tests it seems i was right all along. But the funny thing is in other languages i use map all the time. It's just too awkward in Python and i wish it were not so... Oh well?
From: Lie Ryan on 6 Jun 2010 15:27 On 06/07/10 03:22, rantingrick wrote: > On Jun 6, 12:02 pm, Alain Ketterlin <al...(a)dpt-info.u-strasbg.fr> > wrote: >> rantingrick <rantingr...(a)gmail.com> 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 or so ago. After a few unit tests > it seems i was right all along. But the funny thing is in other > languages i use map all the time. It's just too awkward in Python and > i wish it were not so... Oh well? 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 return [func(g, x) for x in args] foo(map, [[4, 6, 3], [6, 3, 2], [1, 3, 5]]) I'm not going to argue how often that would be useful though.
From: Thomas Jollans on 6 Jun 2010 15:35 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. Sometimes Py2.x map is useful, sometimes list comprehension is nicer. Sometimes Py3.x map / Py2.x itertools.imap is useful, sometimes generator expressions are more elegant. Same goes for filter, by the way.
From: Richard Thomas on 6 Jun 2010 15:48 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 accomplished without map. It is semantically different to mapping a function over a set. As far as speed goes, Python has an overhead for making a function call which means that its often faster to use a for loop. It seems like a rather small difference in speed though and if what you want to do is semantically a map you should write it is a map thereby making your code read like what it does. If it later turns out to slow down your program too much optimise it then. In your second pair of tests the map is faster because str is a builtin and doesn't have that overhead. Additionally the name 'str' is only looked up once rather than 10000 times. :-) Richard.
From: D'Arcy J.M. Cain on 6 Jun 2010 15:54 On Mon, 07 Jun 2010 05:27:43 +1000 Lie Ryan <lie.1296(a)gmail.com> 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 > return [func(g, x) for x in args] > > foo(map, [[4, 6, 3], [6, 3, 2], [1, 3, 5]]) 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. -- D'Arcy J.M. Cain <darcy(a)druid.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Sniffer Linux with Raw Socket Next: Drop Table w/ MySQLdb? |